@RestResource(id="atg.commerce.order.restresources.CartCommerceItemRestSubresource") public class CartCommerceItemRestSubresource extends CommerceItemRestSubresource implements UpdateableRestResource
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
OrderManager |
mOrderManager |
static java.lang.String |
PROP_QUANTITY |
static java.lang.String |
PROP_QUANTITY_WITH_FRACTION |
static java.lang.String |
SHIPPING_GROUP_ID |
static java.lang.String |
ZERO |
COMMERCE_ITEM_ID_PATH_PARAM, ERR_COMMERCE_ITEM_NOT_AVAILABLE_IN_ORDER, mEmbeddedProductRelationshipName, mEmbeddedSkuRelationshipName, mGwpMarkerManager, mItemGWPDiscountInfoRelationshipName, mUnitPricesRelationshipName, REQUESTED_BEANS_QUERY_PARAM, UNITS, VIEW_QUERY_PARAM
DEFAULT_PAGE_SIZE, mEmbeddedCommerceItemRelationshipName, mEmbeddedPaymentGroupRelationshipName, mEmbeddedShippingGroupRelationshipName, RESOURCE_NAME, sResourceBundle
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
CartCommerceItemRestSubresource() |
Modifier and Type | Method and Description |
---|---|
protected void |
addInputsForAddItem(FormHandlerExecutor pExecutor,
Order pOrder,
org.json.JSONObject pInputJson,
atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo,
AddCommerceItemInfo[] pItemsToAdd)
This method provides a place from which to add form handler input during the add item operation.
|
protected void |
addInputsForDeleteItem(FormHandlerExecutor pExecutor,
Order pOrder,
java.lang.String pCommerceItemId)
This method provides a place from which to add form handler input during the delete item operation.
|
protected void |
addInputsForUpdateItems(FormHandlerExecutor pExecutor,
Order pOrder,
atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo)
This method provides a place from which to add form handler input during the update item operation.
|
RepresentationModel |
addItem(org.json.JSONObject pInputJson)
Add an item to the Shopping Cart.
|
protected AddCommerceItemInfo |
buildAddCommerceItemInfo(atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo)
Builds an
AddCommerceItemInfo from the given ResourceUpdateInfo . |
java.lang.Object |
deleteItem(java.lang.String pCommerceItemId)
Deletes a commerce item related to the Order.
|
java.lang.String |
getAddItemsHandleMethod()
Gets the name of the CartModifierFormHandler method that is called for handling the adding of items.
|
java.lang.String |
getCartModifierFormHandlerPath()
Returns the CartModifierFormHandlerPath.
|
protected java.net.URI |
getCreatedItemUri(FormHandlerExecutor pExecutor)
Build a URI to the newly added/created CommerceItem if present.
|
java.lang.String |
getDeleteItemHandleMethod()
Gets the name of the CartModifierFormHandler method that is called for handling the deletion of an item.
|
protected AddCommerceItemInfo[] |
getItemsToAdd(java.util.List<atg.service.jaxrs.ResourceUpdateInfo> pAddUpdateInfos)
Build a list of
AddCommerceItemInfo s obtained from the ResourceUpdateInfo s. |
OrderManager |
getOrderManager()
Returns the OrderManager.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getUpdateData(java.util.List<atg.service.jaxrs.ResourceUpdateInfo> pResourceUpdateInfos)
Builds a map with details of the quantities of the commerce items for update.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getUpdateData(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo,
java.util.List<CommerceItem> pCommerceItems)
Builds a map with details of the quantity of commerce item for update.
|
java.lang.String |
getUpdateItemsHandleMethod()
Gets the name of the CartModifierFormHandler method that is called for handling the updating and adding of items.
|
protected void |
populateDataForUpdate(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo,
java.util.Map<java.lang.String,java.lang.String> pDataForUpdate)
Populates the given map with details of the quantity of commerce item for update.
|
void |
setAddItemsHandleMethod(java.lang.String pAddItemsHandleMethod)
Sets the name of the CartModifierFormHandler method that is called for handling the adding of items.
|
void |
setCartModifierFormHandlerPath(java.lang.String pCartModifierFormHandlerPath)
Sets the CartModifierFormHandlerPath.
|
void |
setDeleteItemHandleMethod(java.lang.String pDeleteItemHandleMethod)
Sets the name of the CartModifierFormHandler method that is called for handling the deletion of an item.
|
void |
setOrderManager(OrderManager pOrderManager)
Sets the OrderManager.
|
void |
setUpdateItemsHandleMethod(java.lang.String pUpdateItemsHandleMethod)
Sets the name of the CartModifierFormHandler method that is called for handling the updating and adding of items.
|
java.net.URI |
update(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo)
Updates the CommerceItems in the Cart.
|
RepresentationModel |
updateItem(java.lang.String pCommerceItemId,
org.json.JSONObject pInputJson)
Updates a commerce item within the current order.
|
RepresentationModel |
updateItems(org.json.JSONObject pInputJson)
Using the PATCH Merge protocol add/remove/update items in the Cart.
|
getCommerceItem, getCommerceItemFromOrder, getEmbeddedProductRelationshipName, getEmbeddedSkuRelationshipName, getGiftWithPurchaseDetails, getGwpMarkerManager, getItemGWPDiscountInfoRelationshipName, getRepresentationModelBuilder, getUnitPriceBeanOverrideFilterId, getUnitPriceBeans, getUnitPriceBeanStateMapKey, getUnitPricesRelationshipName, isRequestedBeanToBeHandled, listCommerceItems, setEmbeddedProductRelationshipName, setEmbeddedSkuRelationshipName, setGwpMarkerManager, setItemGWPDiscountInfoRelationshipName, setUnitPriceBeanOverrideFilterId, setUnitPriceBeanStateMapKey, setUnitPricesRelationshipName
addCreatedItemUri, buildMemberUris, getCartUri, getCreatedItemUri, getDefaultLimit, getEmbeddedCartRelationshipName, getEmbeddedCommerceItemRelationshipName, getEmbeddedPaymentGroupRelationshipName, getEmbeddedShippingGroupRelationshipName, getOrder, getRelationshipCreated, getRelationships, getRepresentationModelBuilder, getRepresentationModelBuilderWithCart, getRepresentationModelBuilderWithCart, getRepresentationModelBuilderWithPaging, getSelfLink, setDefaultLimit, setEmbeddedCartRelationshipName, setEmbeddedCommerceItemRelationshipName, setEmbeddedPaymentGroupRelationshipName, setEmbeddedShippingGroupRelationshipName
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService, toString
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
updateEmbeddedResources
public static final java.lang.String CLASS_VERSION
public static final java.lang.String PROP_QUANTITY_WITH_FRACTION
public static final java.lang.String PROP_QUANTITY
public static final java.lang.String SHIPPING_GROUP_ID
public static final java.lang.String ZERO
public OrderManager mOrderManager
public java.lang.String getCartModifierFormHandlerPath()
public void setCartModifierFormHandlerPath(java.lang.String pCartModifierFormHandlerPath)
pCartModifierFormHandlerPath
- - the CartModifierFormHandlerPath to set.public java.lang.String getDeleteItemHandleMethod()
The default value is "removeItemFromOrder".
public void setDeleteItemHandleMethod(java.lang.String pDeleteItemHandleMethod)
pDeleteItemHandleMethod
- the name of the delete item handle methodpublic java.lang.String getAddItemsHandleMethod()
The default value is "addMultipleItemsToOrder".
public void setAddItemsHandleMethod(java.lang.String pAddItemsHandleMethod)
pAddItemsHandleMethod
- the name of the add items handle methodpublic java.lang.String getUpdateItemsHandleMethod()
The default value is "setOrderByCommerceId".
public void setUpdateItemsHandleMethod(java.lang.String pUpdateItemsHandleMethod)
pUpdateItemsHandleMethod
- the name of the update and add items handle methodpublic OrderManager getOrderManager()
public void setOrderManager(OrderManager pOrderManager)
pOrderManager
- - the OrderManager to set.@Endpoint(id="/{commerceItems}/#POST", validatorId="commerceItems.id-Full", filterId="commerceItems.id-FullWithCart", updateTarget=true) public RepresentationModel addItem(org.json.JSONObject pInputJson) throws RestException, CommerceException, javax.servlet.ServletException
{
{"productId":"xprod2124", "catalogRefId":"xsku2124", "quantity":"232", "siteId":"homeSite", ...}
}
pInputJson
- representation of the item to be addedRestException
- if a problem occurred whilst adding an item to the shopping cartCommerceException
javax.servlet.ServletException
@Endpoint(id="/{commerceItemId}#DELETE", isSingular=true, filterId="commerceItems-Delete") public java.lang.Object deleteItem(java.lang.String pCommerceItemId) throws RestException, javax.servlet.ServletException
As the sub-resource delete can affect the top-level resource details, e.g. order level price info, we deviate from the normal NO_CONTENT response. We return @see atg.service.jaxrs.RepresentationModel with the top-level cart (summary) embedded in the response to reflect any changes. The response state will return the resource collection affected by the delete.
pCommerceItemId
- - the commerce item to look up in the order and delete.RestException
- if a problem occurred whilst deleting the commerce itemjavax.servlet.ServletException
@PATCH @Endpoint(id="/commerceItems/{id}#PATCH", isSingular=true, validatorId="commerceItems.id-Full", filterId="commerceItems.id-FullWithCart", updateTarget=true) public RepresentationModel updateItem(java.lang.String pCommerceItemId, org.json.JSONObject pInputJson) throws RestException, CommerceException, javax.servlet.ServletException
pCommerceItemId
- id of the commerce item to updatepInputJson
- representation of commerce item updates to applyRestException
- if an internal server error occurs while updating the commerce itemCommerceException
- if a shipping group could not be set on the orderjavax.servlet.ServletException
- if a problem occurred whilst adding input to the form handler executor@PATCH @Endpoint(id="/{commerceItems}/#PATCH", validatorId="commerceItems-Full", filterId="commerceItems-DefaultWithCart", updateTarget=true) public RepresentationModel updateItems(org.json.JSONObject pInputJson) throws RestException, CommerceException, javax.servlet.ServletException, TransactionDemarcationException
Example JSON:
{ "items": [ { "id":"ci84000025" }, { "id": "ci82000003", "quantity": 55.5 }, { "productId": "xprod2124", "catalogRefId": "xsku2124", "quantity": 123 } ] }Because the collection is a representation of CommerceItems this leads to an anomaly where the add operation will need to convert the properties received into an AddCommerceItemInfo.
pInputJson
- representation of the items for updateRestException
- if a problem occurred whilst updating the commerce itemsCommerceException
- if a shipping group could not be set on the orderjavax.servlet.ServletException
- if a problem occurred whilst adding input to the form handler executorTransactionDemarcationException
- if a problem occurred during transaction demarcationpublic java.net.URI update(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo) throws RestException
update
in interface UpdateableRestResource
pUpdateInfo
- - update object containing request input and any existing
repository (commerce items) data to be updatedRestException
- - if an issue occurs performing the updateprotected AddCommerceItemInfo buildAddCommerceItemInfo(atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo)
AddCommerceItemInfo
from the given ResourceUpdateInfo
. The
ResourceUpdateInfo
is assumed to be of type CommerceItem
(as defined in the
payload schema).
If you have a customized version of AddCommerceItemInfo
and need to set additional data,
override this method, make a call to super and set the appropriate properties.
pResourceUpdateInfo
- a ResourceUpdateInfo
that represents the item to be addedAddCommerceItemInfo
protected AddCommerceItemInfo[] getItemsToAdd(java.util.List<atg.service.jaxrs.ResourceUpdateInfo> pAddUpdateInfos)
AddCommerceItemInfo
s obtained from the ResourceUpdateInfo
s.pAddUpdateInfos
- a list of ResourceUpdateInfo
detailing the operations to be performed.AddCommerceItemInfo
objectsprotected java.util.Map<java.lang.String,java.lang.String> getUpdateData(java.util.List<atg.service.jaxrs.ResourceUpdateInfo> pResourceUpdateInfos)
The map itself has a key of commerce item id and value of quantity.
pResourceUpdateInfos
- a list of ResourceUpdateInfos containing data for updateprotected java.util.Map<java.lang.String,java.lang.String> getUpdateData(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo, java.util.List<CommerceItem> pCommerceItems)
The map itself has a key of commerce item id and value of quantity.
A list of commerce items are also supplied in order to preserve them during the update. This is due to the underlying logic executed in the form handler call for update.
pUpdateInfo
- contains details of the resource being updatedpCommerceItems
- a list of the other commerce items that exist in the orderprotected void populateDataForUpdate(atg.service.jaxrs.ResourceUpdateInfo pUpdateInfo, java.util.Map<java.lang.String,java.lang.String> pDataForUpdate)
The pDataForUpdate map itself has a key of commerce item id and value of quantity. The quantity is stored as a String in order for the associated form handler to interpret it correctly.
The following actions occur, based on the update type:
pUpdateInfo
- contains details of the resource being updatedpDataForUpdate
- a map of commerce id to (String) quantityprotected void addInputsForAddItem(FormHandlerExecutor pExecutor, Order pOrder, org.json.JSONObject pInputJson, atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo, AddCommerceItemInfo[] pItemsToAdd) throws javax.servlet.ServletException, CommerceException
Note - the pItemsToAdd array is built using the getItemsToAdd(List)
and buildAddCommerceItemInfo(ResourceUpdateInfo)
methods. To ensure additional AddCommerceItemInfo
properties get set, see buildAddCommerceItemInfo(ResourceUpdateInfo)
.
To add additional input, call one of the variants of FormHandlerExecutor.addInput(String, Object)
.
pExecutor
- the form handler executor to which the input should be addedpOrder
- the order to which we want to add the commerce itempInputJson
- representation of the item to be addedpResourceUpdateInfo
- the resource update info representing the item to be addedpItemsToAdd
- the items to add, in a format that that form handler understandsjavax.servlet.ServletException
- if a problem occurred whilst adding input to the executorCommerceException
- if a shipping group could not be set on the orderprotected void addInputsForUpdateItems(FormHandlerExecutor pExecutor, Order pOrder, atg.service.jaxrs.ResourceUpdateInfo pResourceUpdateInfo) throws javax.servlet.ServletException
Additional information is set in the request in a key-value pair format. The key being the commerce item id and the value being the quantity.
To add additional input, call one of the variants of FormHandlerExecutor.addInput(String, Object)
.
pExecutor
- the form handler executor to which the input should be addedpOrder
- the order for which we want to update the commerce itemspResourceUpdateInfo
- the resource update info representing the items to be updatedjavax.servlet.ServletException
- if a problem occurred whilst adding input to the executorprotected void addInputsForDeleteItem(FormHandlerExecutor pExecutor, Order pOrder, java.lang.String pCommerceItemId) throws javax.servlet.ServletException
To add additional input, call one of the variants of FormHandlerExecutor.addInput(String, Object)
.
pExecutor
- the form handler executor to which the input should be addedpOrder
- the order from which we want to delete a commerce itempCommerceItemId
- id of the commerce that should be deletedjavax.servlet.ServletException
- if a problem occurred whilst adding input to the executorprotected java.net.URI getCreatedItemUri(FormHandlerExecutor pExecutor)
CartModifierFormHandler.getAddItemsToOrderResult()
;pExecutor
- - FormHandlerExecutor used in the execution of a given form handler handle operation.