How To Extend An SOI Service With UserData - WCS Tips

Popular Posts

  • Extending an SOI service with UserData C ustomization of the Order noun by using the UserData field. This involves extending the Order noun of the Web services archite...
  • Persistent Sessions in WCS WebSphere Commerce can be configured to enable persistent sessions. This enables some session-related information of the registered or gues...
  • WCS Data Cache Data that is cached by the WebSphere Commerce data cache can be configured by using either the command caching or DistributedMap objects c...
  • WCS Calculation Framework WCS need to calculate monetary amounts and apply them to business objects. Business rules and legal requirements specify how and when thes...
  • WCS Commands in Catalog Subsystem The Catalog Subsystem contains all logic and data relevant to an online catalog, including catalog groups (or categories), catalog entries...
  • Store with Multiple Languages and Multiple Currencies What if a store has to support multiple currencies to sell based on the language/country ? Here is a smal POC done to make it work. PFB...
  • WCS Order Management Commnds The Order Management subsystem includes all logic and data relevant to placing, processing, and managing orders.  This is done using variou...
  • WCS Subsystems WCS framework is majorly used fo E-Commerce Sites development on basis of many subsystems, which helps in developing and integrating diffe...
  • WCS Promotions Promotions provide the ability to offer customers incentives to purchase. WebSphere Commerce supports numerous types of promotions. For e...
  • WCS Payment Subsystem The Payments subsystem helps us manage the payment information. It connects to Payment Service Providers by using payment plug-ins. Paymen...

How to extend an SOI service with UserData ?

Order SOI Service is taken up here to explain. Steps to extend are as follows:
  • Create three new classes.
  • ExtOrderFacadeClient.java, extends the client API library(OrderFacadeClient) to a value for the field1 column for Orders table
  • ExtExtendOrderItemProcessCmdImpl.java, extends ExtendOrderItemProcessCmdImpl and persists the field1 value passed in the ORDERS.FIELD1 column
  • ExtComposeOrderDetailsCmdImpl.java, extends ComposeOrderDetailsCmdImpl and retrieves the field1 value from the ORDERS.FIELD1 column
  • Open ExtOrderFacadeClient.java and replace the contents with the following code:
package com.custom.order.commands.order.commands;import java.util.Iterator;import java.util.Map;import javax.security.auth.callback.CallbackHandler;import com.ibm.commerce.foundation.common.datatypes.BusinessContextType;import com.ibm.commerce.foundation.common.datatypes.CommerceFoundationFactory;import com.ibm.commerce.foundation.common.datatypes.UserDataType;import com.ibm.commerce.order.facade.client.OrderException;import com.ibm.commerce.order.facade.client.OrderFacadeClient;import com.ibm.commerce.order.facade.datatypes.OrderType;/** * ExtOrderFacadeClient will extend OrderFacadeClient. This customization will * extend the Change noun to include new personalization attributes for * the Order noun. */public class ExtOrderFacadeClient extends OrderFacadeClient{ private static final String CLASSNAME = ExtOrderFacadeClient.class.getName(); private static final java.util.logging.Logger LOGGER = com.ibm.commerce.foundation.common.util.logging.LoggingHelper.getLogger(ExtOrderFacadeClient.class); public ExtOrderFacadeClient(){ super(); } public ExtOrderFacadeClient(BusinessContextType businessContext, CallbackHandler callbackHandler) { super(businessContext, callbackHandler); } @Override protected OrderType buildOrder(Map parameters, String actionName) throws OrderException { final String strMethodName = "buildOrderItem"; LOGGER.entering(CLASSNAME, strMethodName); OrderType orderType = super.buildOrder(parameters, actionName); String field1 = ""; Iterator keys = parameters.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.startsWith("field1")) { field1 = ((String[])parameters.get(key))[0]; } } UserDataType userData = orderType.getUserData(); if (userData == null) { userData = CommerceFoundationFactory.eINSTANCE.createUserDataType(); } orderType.setUserData(userData); Map userDataFields = userData.getUserDataField(); userDataFields.put("field1", field1); return orderType; }}
  • ExtendOrderItemProcessCmdImpl is the component command that is required to be changed to handle the new information inside the extended UserData. The new command takes the new personalization parameters out of the response properties and persists them to the database.
  • Open MyExtendedOrderItemProcessCmdImpl.java and replace the contents with the following code:
package com.custom.order.commands.order.commands;import java.util.Enumeration;import org.apache.commons.lang.StringUtils;import com.ibm.commerce.datatype.TypedProperty;import com.ibm.commerce.exception.ECException;import com.ibm.commerce.order.objects.OrderAccessBean;import com.ibm.commerce.orderitems.commands.ExtendOrderItemProcessCmdImpl; /** * When the message is received, the request properties will be processed by the command * ExtendOrderItemProcessCmdImpl, so we extend this command and put our new logic into the * performExecute() method. This logic will write the new personalization data into the ORDERS.FIELD1 */public class ExtExtendOrderItemProcessCmdImpl extends ExtendOrderItemProcessCmdImpl{ private static final String CLASSNAME = ExtExtendOrderItemProcessCmdImpl.class.getName(); private static final java.util.logging.Logger LOGGER = com.ibm.commerce.foundation.common.util.logging.LoggingHelper.getLogger(ExtExtendOrderItemProcessCmdImpl.class); private TypedProperty myRequestProperties; public ExtExtendOrderItemProcessCmdImpl(){ super(); } public void setRequestProperties(TypedProperty aRequestproperties) throws ECException{ myRequestProperties = aRequestproperties; super.setRequestProperties(aRequestproperties); } public void performExecute() throws ECException{ final String METHODNAME = "performExecute"; LOGGER.entering(CLASSNAME, METHODNAME); super.performExecute(); if(myRequestProperties!=null){ Enumeration keys = myRequestProperties.keys(); String field1 = "", orderId = ""; while (keys.hasMoreElements()) { String keyName = (String)keys.nextElement(); if (keyName.startsWith("field1")) { field1 = (String)myRequestProperties.get(keyName); } if (keyName.startsWith("resolvedOrderIds")) { orderId = ((String[])myRequestProperties.get(keyName))[0]; } } try { if(!StringUtils.isEmpty(field1)) { OrderAccessBean orderAccessBean = new OrderAccessBean(); orderAccessBean.setInitKey_orderId(orderId); orderAccessBean.refreshCopyHelper(); orderAccessBean.setField1(field1); orderAccessBean.commitCopyHelper(); } } catch(Exception exception) { System.out.println(exception); } } LOGGER.exiting(CLASSNAME, METHODNAME); } }
  • ExtComposeOrderDetailsCmdImpl.java returns ORDERS.FIELD1
  • Open ExtComposeOrderDetailsCmdImpl.java and replace the contents with the following code:
package com.custom.order.commands.order.commands;import java.util.List;import java.util.Map;import java.util.logging.Logger;import com.ibm.commerce.foundation.common.datatypes.CommerceFoundationFactory;import com.ibm.commerce.foundation.common.datatypes.UserDataType;import com.ibm.commerce.foundation.common.util.logging.LoggingHelper;import com.ibm.commerce.order.facade.datatypes.OrderType;import com.ibm.commerce.order.facade.datatypes.ShowOrderType;import com.ibm.commerce.order.facade.server.commands.ComposeOrderDetailsCmdImpl;import com.ibm.commerce.order.objects.OrderAccessBean;import com.ibm.websphere.command.CommandException;public class ExtComposeOrderDetailsCmdImpl extends ComposeOrderDetailsCmdImpl { private static final String CLASSNAME = "com.custom.order.commands.order.commands.XComposeOrderDetailsCmdImpl"; private static final Logger LOGGER = LoggingHelper.getLogger(CLASSNAME); @Override protected ShowOrderType composeOrderDetail(List avOrders) throws CommandException { ShowOrderType showOrderType = super.composeOrderDetail(avOrders); List ordNouns =showOrderType.getDataArea().getOrder(); try { for(Object ordNoun :ordNouns) { OrderAccessBean orderAccessBean = new OrderAccessBean(); OrderType orderType = (OrderType)ordNoun; orderAccessBean.setInitKey_orderId(orderType.getOrderIdentifier().getUniqueID()); orderAccessBean.refreshCopyHelper(); UserDataType userData = orderType.getUserData(); if(orderAccessBean != null) { if(userData == null) { userData = CommerceFoundationFactory.eINSTANCE.createUserDataType(); } orderType.setUserData(userData); Map userDataFields = userData.getUserDataField(); userDataFields.put("field1",orderAccessBean.getField1()); } } } catch(Exception exception) { System.out.println(exception); } return showOrderType; }}
  • Register the new commands
INSERT INTO CMDREG(STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET)VALUES (0,'com.ibm.commerce.orderitems.commands.ExtendOrderItemProcessCmd','com.ibm.commerce.custom.order.commands.ExtExtendOrderItemProcessCmdImpl','Local'); UPDATE CMDREG SET CLASSNAME ='com.ibm.commerce.custom.order.commands.ExtComposeOrderDetailsCmdImpl' WHERE INTERFACENAME='com.ibm.commerce.order.facade.server.commands.ComposeOrderCmd+IBM_Details';
  • Register the new Client API
    • In WebSphere Commerce Developer, open the Enterprise Explorer view , and expand Stores > WebContent > WEB-INF .
    • Open struts-config-ext.xml.
    • Copy the following text into the bottom of the file, before the </struts-config> tag:
<plug-in className="com.ibm.commerce.struts.ComponentPlugIn"> <set-property property="componentId" value="order"/> <set-property property="clientFacadeClassName" value="com.ibm.commerce.custom.order.commands.ExtOrderFacadeClient"/> </plug-in>
    • Save and close the file.
Hit the following URL and observe that the ORDERS.FIELD1 value is 5. Without this customization, field1 will be null. http://localhost/webapp/wcs/stores/servlet/OrderChangeServiceItemAdd?field1=5&doInventory=N&catEntryId=12345&calculationUsage=-1%2C-3&calculateOrder=1&orderId=.&langId=-20&storeId=11151&URL=ShopCartDisplayView&quantity=1 For more details please refer to the below link in infocenter. http://www.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.component-services.doc/tutorial/twvuserdatatutorial.htm

1 comment:

  1. Unknown20 April 2017 at 22:47

    Amazing blog! It was such a valuable information. Thank you for sharing.Website Development services in Bangalore | website development company Bangalore | Ecommerce website development Bangalore | ecommerce development Bangalore

    ReplyDeleteReplies
      Reply
Add commentLoad more... Home Subscribe to: Comments (Atom)
  • Home
  • WCS Subsystems
  • Catalog Subsystem
  • Order Management Subsystem
  • Payment Subsystem
  • Member Subsystem
  • Marketing Subsystem
  • Promotion Engine
  • Promotions
  • Calculation framework
  • Calculation of Shipping Charge
  • Payment Processing Flow
  • Creating a new Payment Method
  • Business Tools
  • How to evaluate promotion without user adding the ...
  • Redirect vs Forward
  • WCS Persistence Layer
  • Inventory Systems
  • ATP vs Non-ATP Inventory
  • Commands in the Order Flow
  • Classification of Catalog Entries
  • Design Patterns in WCS
  • Caching
  • How to install Cache Monitor ?
  • Cache Invalidation
  • How to import certificate file and its private key...
  • Dynamic Kits Data model and Order flow
  • Enabling Persistent Sessions in WCS
  • STRUTS action-mapping properties

Blog Archive

  • ▼  2017 (2)
    • ▼  October (1)
      • WCS Data Cache

About Me

Uma Govindaraj A WCS developer View my complete profile

Total Pageviews

Tag » Com.ibm.commerce.order.facade.datatypes.ordertype