Thursday, May 7, 2015

Some useful methods in IBM WCS


/***** Getting DB connection and run direct SQL ******/

public class CommonJDBCHelperBean extends BaseJDBCHelper implements SessionBean {
private String fetchPhysicalStoresSQL = "select stloc_id, identifier, address1, address3, country from stloc where latitude = ? order by address1"
                  + READONLY_WITH_UR_CLAUSE;

                /**
                 * It fetches list of all active stores address details from STLOC table.
                 *
                 * @return Vector - list of StoreLocationObjectBean
                 * @throws NamingException
                 *             If failed to get SQL connection
                 * @throws SQLException
                 *             if failed to execute SQL query
                 */
                public Vector fetchPhysicalStores(String storeId) throws NamingException, SQLException {
                                final String methodName = "fetchPhysicalStores";
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                Vector vPhysicalStore = new Vector();
                                PreparedStatement stmt = null;
                                ResultSet rs = null;
                                try {
                                                makeConnection();
                                                if (logger.isLoggable(TraceIdentifiers.DEBUG_OUTPUT)) {
                                                                logger.logp(TraceIdentifiers.DEBUG_OUTPUT, CLASS_NAME, methodName, "sql is[{0}]",
                                                                                                fetchPhysicalStoresSQL.toString());
                                                }
                                                stmt = getPreparedStatement(fetchPhysicalStoresSQL);
                                                stmt.setBigDecimal(1, new BigDecimal(storeId));
                                                rs = executeQuery(stmt, false);
                                                while (rs.next()) {
                                                                StoreLocationObjectBean storeLocationObjectBean = new StoreLocationObjectBean();
                                                                storeLocationObjectBean.setStloc_id(rs.getString(1));
                                                                storeLocationObjectBean.setIdentifier(rs.getString(2));
                                                                storeLocationObjectBean.setAddress1(rs.getString(3));
                                                                storeLocationObjectBean.setAddress3(rs.getString(4));
                                                                storeLocationObjectBean.setCountry(rs.getString(5));
                                                                vPhysicalStore.add(storeLocationObjectBean);
                                                }
                                } finally {
                                                closeConnection();
                                                if (null != rs) {
                                                                rs.close();
                                                }

                                                if (null != stmt) {
                                                                stmt.close();
                                                }
                                }
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                return vPhysicalStore;

                }

/********* To send XML in QUEUE ***************/

To send OR02XML

Insert in msgtype:
insert into msgtypes values(10002,1,'OR02MIGRATION','OR02MIGRATION','Abster Send OR02 XML Message for completed Orders',null);


SendMsgCmd sendXMLCmd = (SendMsgCmd) CommandFactory
                                                                        .createCommand(SendMsgCmd.NAME, oaBean.getStoreEntityIdInEJBType());
                                                sendXMLCmd.setMsgType("OR02MIGRATION");
                                                sendXMLCmd.setStoreID(oaBean.getStoreEntityIdInEJBType());
// get clone of request to put additional values
                                                TypedProperty properties = (TypedProperty) getRequestProperties()
                                                                        .clone();
properties.put("ordersId", ordersId);
properties.put("OrderRefNumber", ordersId);
properties.put("LanguageId", -1);
sendXMLCmd.compose(OR02_VIEW,getCommandContext(), properties);
sendXMLCmd.sendTransacted();
sendXMLCmd.setCommandContext(getCommandContext());

sendXMLCmd.execute();



*****************Session *******************
<c:choose>
<c:when test="${userType == 'G' || fn:contains(userEmail,'@X.XX')|| user_id == '-1002'}">
<%
session.setAttribute("eMarketsubscriberBeanRequired","N");
session.setAttribute("subscriberBean",new com.xxxx.commerce.subscribers.commands.EmailServiceDataBean());
%>

</c:when>

<c:otherwise>

<wcbase:useBean id="bnRegister" classname="com.ibm.commerce.user.beans.UserRegistrationDataBean" >
<c:set value="${CommandContext.user.userRegistry.userId}" target="${bnRegister}" property="userId"/>
</wcbase:useBean>
<c:set var="service_Id"><fmt:message key="SUBSCRIPTION_DEFAULT_SERVICE_ID" bundle="${storeFrontText}"/></c:set>
<c:set var="qubituserEmail" value="${bnRegister.email1}" />
<c:if test="${!fn:contains(qubituserEmail,'@X.XX')|| user_id == '-1002'}">
<%
Object isAlreadyAvailable= session.getAttribute("eMarketsubscriberBeanRequired");                                            
              if(null != isAlreadyAvailable && isAlreadyAvailable.toString().equals("N")) {                                          

%>
<wcbase:useBean id="bean" classname="com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean">
<c:set value="${service_Id}" target="${bean}" property="inputVal" />
<c:set value="${qubituserEmail}" target="${bean}" property="userEmail"/>
<c:set value="${userType}" target="${bean}" property="userType"/>
</wcbase:useBean>
<%
session.setAttribute("eMarketsubscriberBeanRequired","Y");
session.setAttribute("subscriberBean",bean);
}
%>    
</c:if>

</c:otherwise>
</c:choose>


Using it

<%@include file="QubitMarketing.jspf"%>
<%
com.xxxxxx.commerce.subscribers.commands.EmailServiceDataBean subscriberBean=(com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean)session.getAttribute("subscriberBean"); 
if(subscriberBean!= null && subscriberBean.getSubscriberId() > 0 && subscriberBean.getSubscriptionId()>0 && subscriberBean.getSubscriptionStatus()>0){%>,
"subscriber_id": "<c:out value="${subscriberBean.subscriberId}" />",
"subscription_id": "<c:out value="${subscriberBean.subscriptionId}" />"<%} %>

Creating data bean
public class EmailServiceDataBean implements SmartDataBean {
private static final String CLASS_NAME = EmailServiceDataBean.class
.getName();
private static final Logger logger = Logger.getLogger(CLASS_NAME);
private Long subscriberId;
private String emailAddress;
private Integer brandId;
private String userEmail;
protected Integer Key_emailServiceId;
private String userType;
private Long subscriptionId;
private Short subscriptionStatus;
public CommandContext iCommandContext = null;
public TypedProperty requestProperties = null;

public String getUserType() {
return userType;
}

public void setUserType(String userType) {
this.userType = userType;
}

protected String inputVal;

public String getInputVal() {
return inputVal;
}

public void setInputVal(String inputVal) {
this.inputVal = inputVal;
}

public Integer getKey_emailServiceId() {
return Key_emailServiceId;
}

public void setKey_emailServiceId(Integer key_emailServiceId) {
Key_emailServiceId = getKey_emailServiceId();
}

public String getUserEmail() {
return userEmail;
}

public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public Long getSubscriberId() {
return subscriberId;
}

public void setSubscriberId(Long subscriberId) {
this.subscriberId = subscriberId;
}

public String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public Integer getBrandId() {
return brandId;
}

public void setBrandId(Integer brandId) {
this.brandId = brandId;
}

@Override
public void populate() throws Exception {
final String METHOD_NAME = "populate";
if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// EmailServiceAccessBean is initilize to get brand_id from
// EMAIL_SERVICE table
EmailServiceAccessBean emailServiceAccessBean = new EmailServiceAccessBean();
emailServiceAccessBean.setInitKey_emailServiceId(Integer
.valueOf(getInputVal()));
emailServiceAccessBean.refreshCopyHelper();
brandId = emailServiceAccessBean.getBrandId();
// Guest user check. If user is of type guest then emailId will not
// available
System.out.println("brandId"+brandId);
System.out.println("getInputVal()"+getInputVal());
try {
if (!getUserType().equals("G") && !getUserEmail().equals(null)) {
// subscriberId from SubscriberAccessBean
SubscriberAccessBean subscriberAccessBean = new SubscriberAccessBean();
subscriberAccessBean.findByBrandIdAndEmailAddress(brandId,
getUserEmail());
Enumeration subscriberIds = null;
subscriberIds = subscriberAccessBean
.findByBrandIdAndEmailAddress(brandId, getUserEmail());
if (subscriberIds != null) {
boolean count = true;
while (subscriberIds.hasMoreElements() && count == true) {
subscriberId = ((SubscriberAccessBean) (subscriberIds
.nextElement())).getSubscriberId();
count = false;
}
}
// subscriptionId from SubscriptionsAccessBean
System.out.println("subscriberId"+subscriberId);
Enumeration subscriptionIds = null;
Enumeration subscriptionStatuss = null;
SubscriptionsAccessBean subscriptionsAccessBean = new SubscriptionsAccessBean();
try {
if (subscriberId != null) {
subscriptionIds = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
subscriptionStatuss = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
if (subscriptionIds != null) {
boolean count1 = true;
while (subscriptionIds.hasMoreElements()) {
subscriptionId = ((SubscriptionsAccessBean) (subscriptionIds
.nextElement())).getSubscriptionId();
count1 = false;
}
}
if (subscriptionStatuss != null) {
boolean count1 = true;
while (subscriptionStatuss.hasMoreElements()) {
subscriptionStatus = ((SubscriptionsAccessBean) (subscriptionStatuss
.nextElement()))
.getSubscriptionStatus();
count1 = false;
}
}
}
} catch (NullPointerException e) {
System.out.println("subscriberId is null ..."
+ e.getMessage());
}
}
} catch (Exception e) {
System.out.println("No Record Found ...." + e.getMessage());
}

if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}

public Long getSubscriptionId() {
return subscriptionId;
}

public void setSubscriptionId(Long subscriptionId) {
this.subscriptionId = subscriptionId;
}

public Short getSubscriptionStatus() {
return subscriptionStatus;
}

public void setSubscriptionStatus(Short subscriptionStatus) {
this.subscriptionStatus = subscriptionStatus;
}

@Override
public void setCommandContext(CommandContext commandContext) {
iCommandContext = commandContext;
}

@Override
public void setRequestProperties(TypedProperty reqProp) throws Exception {
requestProperties = reqProp;
}

@Override
public CommandContext getCommandContext() {
return iCommandContext;
}

@Override
public TypedProperty getRequestProperties() {
return requestProperties;
}

}

No comments:

Post a Comment