Friday, February 8, 2013

Facebook meta tags using commerce JSP

This post goes through an example from commerce JSP to generate, FaceBook meta tags. The code snippet below prints the meta tags for 2 different kinds of commerce product types, Items and Packages. Based on the type of the product, a different commerce data bean is selected.

Thursday, January 31, 2013

Optimistic locking implementation in EJB

If you are using EJB's in WCS and optimistic locking avoids database deadlocks and helps lower locks placed on the database and allows more applications to run concurrently against the database.Optimistic locking is implemented by creating OPTCOUNTER column for each table.

1) Add OPTCOUNTER column in the table and optCounter CMP field with unchecked getter\setter methods option in creating new field in CMP bean.
2) Map the table OPTCOUNTER to the optCounter field as a CMP managed field, I see this step missing for all EJB's currently implemented so I did not add optCounter mapping either for the new EJB.
3) Adding this.initializeOptCounter(new XCustomKey(this.customId))  in ejbCreate method()
4) Adding optimistic locking in DeploymentDescriptor --> Bean tab, by checking the Concurrency Control (Enable Optimistic locking)
 5) Adding triggers for optCounter and also a file to add these.

CREATE or REPLACE TRIGGER perf_xcustom_1 before update ON XCUSTOM for each row
WHEN ((new.optcounter is null) or (new.optcounter = old.optcounter))
begin if (:old.optcounter < 32767) then :new.optcounter := :old.optcounter + 1; else :new.optcounter := 1; end if; END;

From Infocenter explanation for implementing trigger:
For optimistic locking to work properly, every query that updates a database table row must increment the OPTCOUNTER column value, or reset it to 1 when the current value is 32767. The WebSphere Commerce server uses this technique. However, if database table rows are updated by other code or manual procedures that do not update the OPTCOUNTER column values, then the database triggers defined in the WC_installdir/schema/db_type/wcs.perf.trigger.sql (where db_type is the database type (DB2, Oracle)) schema files ensure that the OPTCOUNTER column values are incremented properly.

Reference:
http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.admin.doc/concepts/cpmoptlock.htm

On redirect removing properties from request


Removing parameters from request when redirecting in commerce is an interesting problem and this is not something that needs to be implemented in regular flows.
In the scenario when you have logonId and logonPassword  passed into form post, removing logonId/logonPassword from request properties in perform execute or creating a new request property and setting in command context does not fix the issue.

responseProp.put(ECConstants.EC_VIEWTASKNAME,ECConstants.EC_GENERIC_REDIRECTVIEW);
responseProp.put(ECConstants.EC_REDIRECTURL,"RedirectViewSample");
setResponseProperties(responseProp);

Solution: OverRide setViewInputProperties and remove the properties from request to the redirect view.

   public void setViewInputProperties(TypedProperty reqProperties){
        reqProperties.remove("logonId");
        reqProperties.remove("logonPassword");       
        this.viewReqProperties = reqProperties;
    }

Tuesday, December 4, 2012

Access control for Views

The data load project in V7 makes, it really easy to load the access control changes. This blog explains a sample custom view access policies for guest and registered user and how this can be verified in the database using the query below. Even for guest users to access views, it is required for the view to belong to AllSiteUsersViews policy. If one tries to create a view and  access it, you would get the following error below and -1002 is (generic user). The first time user comes on a site, it would run user as generic user and as soon as it tries to perform any action specific to a user such as add to cart, it is converted to a guest user.

Error without policy:
AccManager isAllowed CMN1501E: User -1002 does not have the authority to perform action "NewView" on resource "com.ibm.commerce.command.HttpForwardViewCommandImpl" for command "null".

view_acpolicies.xml

<!DOCTYPE Policies SYSTEM "../dtd/accesscontrolpolicies.dtd">
<Policies>
<Action Name="GuestView" CommandName="GuestView" />
        <Action Name="RegisteredView" CommandName="RegisteredView" />
   <!-- Guest USERS VIEWS -->
<ActionGroup Name="AllSiteUsersViews" OwnerID="RootOrganization">
<ActionGroupAction Name="GuestView" />
</ActionGroup>

  <!-- REGISTERED USERS VIEWS -->
<ActionGroup Name="RegisteredUserViews" OwnerID="RootOrganization">
<ActionGroupAction Name="RegisteredView" />
  </ActionGroup>

</Policies>
-------------------------------------------------
select * from acpolicy where acactgrp_id in (select acactgrp_id
from acactactgp where acaction_id
in (select ACACTION_ID from ACACTION where ACTION = 'GuestView'))

Friday, November 9, 2012

SOLR adding custom attributes in SRCHATTRPROP !


If you need to filter SOLR queries based on a dynamic attribute. In the sample java code below the value for the custom attribute _custom.ItemType is retrieved from SRCHATTRPROP table. The code uses out of the box getIndexColumnNameByType on SolrSearchConfigurationRegistry object to retrieve the custom attribute value.

Monday, November 5, 2012

Elite Store Order Flow JSPs

Out of the box V7->EliteStorefrontAssetStore ->Order flow.
Useful to check for JSP's in a certain flow quickly. I have moved header\footer\mincart\breadcrumb\leftside\rightside\espot JSP's to the bottom.Internally it calls multiple JSP fragments that are not captured here.

Cart --> ViewName->AjaxOrderItemDisplayView
Starting point of flow JSP::OrderItemDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/ShopcartSection/OrderItemDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/OrderCreationSection/RequisitionListSubsection/RequisitionListPopupDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/OrderCreationSection/RequisitionListSubsection/RequisitionListPopupTableDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionChoiceOfFreeGiftsPopupContent.jsp
/EliteStorefrontAssetStore/ShoppingArea/ShopcartSection/ShopCartDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Order/Cart/ShipmodeSelectionExt.jsp
/EliteStorefrontAssetStore/Snippets/Order/Cart/OrderItemDetail.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionPickYourFreeGift.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentOrderTotalsSummary.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionCodeDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/CouponWalletTable.jsp
/EliteStorefrontAssetStore/Snippets/Order/Cart/CheckoutLogon.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedHeaderDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/ESpot/CachedContentAreaESpot.jsp
/EliteStorefrontAssetStore/include/MiniShopCartDisplay.jsp
/EliteStorefrontAssetStore/include/BreadCrumbTrailDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedLeftSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedRightSidebarDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/ESpot/ESpotNavDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedFooterDisplay.jsp

Shipping and Billing page--> OrderShippingBillingView
Starting point of flow JSP:OrderShippingBillingDetails.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/OrderShippingBillingDetails.jsp
/EliteStorefrontAssetStore/ShoppingArea/OrderCreationSection/RequisitionListSubsection/RequisitionListPopupDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/OrderCreationSection/RequisitionListSubsection/RequisitionListPopupTableDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/ShippingDetailsDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionChoiceOfFreeGiftsPopupContent.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/ShippingAddressSelect.jsp
/EliteStorefrontAssetStore/Snippets/Member/Address/AddressDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentShippingMethodDetails.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentShipChargeExt.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/OrderItemDetails.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionPickYourFreeGift.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentOrderTotalsSummary.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/PromotionCodeDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Promotions/CouponWalletTable.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/ScheduleOrderDisplayExt.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/BillingAddressDropDownDisplay.jsp
/EliteStorefrontAssetStore/Snippets/EDP/PaymentMethods/Empty.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedHeaderDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/ESpot/CachedContentAreaESpot.jsp
/EliteStorefrontAssetStore/include/MiniShopCartDisplay.jsp
/EliteStorefrontAssetStore/include/BreadCrumbTrailDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedLeftSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedRightSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedFooterDisplay.jsp

 Order Summary page-->SingleShipmentOrderSummaryView
 Starting point of flow JSP:BillingAddressDropDownDisplay
 /EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/BillingAddressDropDownDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Member/Address/AddressDisplay.jsp
/EliteStorefrontAssetStore/Snippets/EDP/PaymentMethods/StandardCOD.jsp
/AjaxActionResponse.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/OrderTotalInJSON.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentSummary.jsp
/EliteStorefrontAssetStore/include/MiniShopCartDisplay.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/OrderItemDetailSummary.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentOrderTotalsSummary.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/ScheduleOrderDisplayExt.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedHeaderDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/ESpot/CachedContentAreaESpot.jsp
/EliteStorefrontAssetStore/include/BreadCrumbTrailDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedLeftSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedRightSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedFooterDisplay.jsp

Order Confirmation page-->OrderShippingBillingConfirmationView
Starting point of flow JSP:OrderReceivedNotify.jsp
/EliteStorefrontAssetStore/Messages/OrderReceivedNotify.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/Content/ContentSpotDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Member/Address/AddressDisplay.jsp
/AjaxActionResponse.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/OrderShippingBillingConfirmationPage.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/OrderItemDetailSummary.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/SingleShipment/SingleShipmentOrderTotalsSummary.jsp
/EliteStorefrontAssetStore/ShoppingArea/CheckoutSection/ScheduleOrderDisplayExt.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedHeaderDisplay.jsp
/EliteStorefrontAssetStore/Snippets/Marketing/ESpot/CachedContentAreaESpot.jsp
/EliteStorefrontAssetStore/include/MiniShopCartDisplay.jsp
/EliteStorefrontAssetStore/include/BreadCrumbTrailDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedLeftSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedRightSidebarDisplay.jsp
/EliteStorefrontAssetStore/include/styles/style1/CachedFooterDisplay.jsp

Thursday, November 1, 2012

Increase HeapSize on server.xml for OutOfMemory Exception

If you are running SOLR or any other high memory process, there is a chance, you have seen the OutOfMemory exception. You can increase the heap-size using WAS or directly in the file. Recommended approach would be directly in the file. 

From WAS console:
  1. In the administrative console, click Servers > Server Types > WebSphere application servers, and then click on an application server name.
  2. In the Server Infrastructure section, click Java and process management > Process definition .
Directly updating the file, as this is the same file that gets updated while changing WAS console: On toolkit, this would be the path
C:\WCDE_ENT70\wasprofile\config\cells\localhost\nodes\localhost\servers\server1\server.xml
Search for initialHeapSize and maximumHeapSize and change 
initialHeapSize=512
maximumHeapSize=1536
or you have only 1024 try
initialHeapSize=1024
maximumHeapSize=1024
If you give incorrect values here, it could result in your server not starting so please be cognizant about that.