package com.ibm.commerce.sample.commands;
import com.ibm.commerce.command.ControllerCommand;
public interface MyNewControllerCmd extends ControllerCommand {
static final String defaultCommandClassName=
"com.ibm.commerce.sample.commands.MyNewControllerCmdImpl";
public String getUserName();
public void setUserName(String userName);
public Integer getPoints();
public void setPoints(Integer points);
}
package com.ibm.commerce.sample.commands;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;
import com.ibm.commerce.accesscontrol.AccessVector;
import com.ibm.commerce.command.CommandFactory;
import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.datatype.TypedProperty;
import com.ibm.commerce.exception.ECApplicationException;
import com.ibm.commerce.exception.ECException;
import com.ibm.commerce.exception.ParameterNotFoundException;
import com.ibm.commerce.ras.ECMessage;
import com.ibm.commerce.ras.ECMessageHelper;
import com.ibm.commerce.sample.databeans.MyNewDataBean;
import com.ibm.commerce.sample.databeans.XBonusEJBDataBean;
import com.ibm.commerce.server.ECConstants;
import com.ibm.commerce.user.objects.UserAccessBean;
import com.ibm.commerce.user.objects.UserRegistryAccessBean;
import com.ibm.ejb.sample.XBonusEJBAccessBean;
public class MyNewControllerCmdImpl extends ControllerCommandImpl implements
MyNewControllerCmd {
String userName;
Integer points;
AccessVector resources = null;
//BonusAccessBean bonusAccessBean;
XBonusEJBAccessBean bonusAccessBean;
UserRegistryAccessBean userRegistryAccessBean;
@Override
public AccessVector getResources() throws ECException {
String refNum = null;
try {
userRegistryAccessBean = new UserRegistryAccessBean();
userRegistryAccessBean = userRegistryAccessBean
.findByUserLogonId(getUserName());
refNum = userRegistryAccessBean.getUserId();
System.out.println("++++++++++++++++"+refNum);
} catch (Exception e) {
e.printStackTrace();
}
bonusAccessBean = new XBonusEJBAccessBean();//new BonusAccessBean();
if (refNum != null) {
try {
bonusAccessBean.setInitKey_memberId(new Long(refNum));
bonusAccessBean.refreshCopyHelper();
resources = new AccessVector(bonusAccessBean);
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (FinderException e) {
UserAccessBean uab = new UserAccessBean();
uab.setInitKey_MemberId(refNum);
resources = new AccessVector(uab);
} catch (NamingException e) {
e.printStackTrace();
}
}
return resources;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getPoints() {
return points;
}
public void setPoints(Integer points) {
this.points = points;
}
@Override
public void performExecute() throws ECException {
// TODO Auto-generated method stub
super.performExecute();
TypedProperty resProp = new TypedProperty();
resProp.put("controllerParm1", "Hello From IBM!!!");
resProp.put("controllerParm2", "Have a Nice Day!!!");
MyNewDataBean mndb = new MyNewDataBean();
mndb.setCalledByControllerCmd(true);
mndb.setCallingCommandName(this.getClass().getName());
mndb.setUserName(getUserName());
mndb.setPoints(getPoints());
resProp.put("mndbInstance", mndb);
MyNewTaskCmd taskCmd = null;
try {
taskCmd = (MyNewTaskCmd) CommandFactory.createCommand(
"com.ibm.commerce.sample.commands.MyNewTaskCmd",
getStoreId());
taskCmd.setCommandContext(getCommandContext());
taskCmd.setInputPoints(getPoints());
taskCmd.setInputUserName(getUserName());
taskCmd.setXBonusEJBAccessBean(bonusAccessBean);
taskCmd.setUserRegistryAccessBean(userRegistryAccessBean);
taskCmd.execute();
if (taskCmd.getGreetings() != null)
resProp.put("taskOutputGreetings", taskCmd.getGreetings());
if (taskCmd.getFoundUserId() != null)
resProp.put("taskOutputUserId", taskCmd.getFoundUserId());
//BonusDataBean bdb=new BonusDataBean(bonusAccessBean);
XBonusEJBDataBean bdb = new XBonusEJBDataBean(bonusAccessBean);
if(taskCmd.getOldBonusPoints()!=null)
resProp.put("oldBonusPoints", taskCmd.getOldBonusPoints());
System.out.println("*******************"+bdb.getBonusPoint());
resProp.put("bdbInstance", bdb);
} catch (Exception e) {
// TODO: handle exception
}
resProp.put(ECConstants.EC_VIEWTASKNAME, "MyNewView");
setResponseProperties(resProp);
}
@Override
public void validateParameters() throws ECException {
// TODO Auto-generated method stub
super.validateParameters();
TypedProperty reqProp = getRequestProperties();
try {
setUserName(reqProp.getString("input1"));
} catch (ParameterNotFoundException e) {
throw new ECApplicationException(
ECMessage._ERR_MISSING_CMD_PARAMETER, this.getClass()
.getName(), "validateParameters", ECMessageHelper
.generateMsgParms(e.getParamName()));
}
setPoints(reqProp.getInteger("input2", 0));
}
}
import com.ibm.commerce.command.ControllerCommand;
public interface MyNewControllerCmd extends ControllerCommand {
static final String defaultCommandClassName=
"com.ibm.commerce.sample.commands.MyNewControllerCmdImpl";
public String getUserName();
public void setUserName(String userName);
public Integer getPoints();
public void setPoints(Integer points);
}
package com.ibm.commerce.sample.commands;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;
import com.ibm.commerce.accesscontrol.AccessVector;
import com.ibm.commerce.command.CommandFactory;
import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.datatype.TypedProperty;
import com.ibm.commerce.exception.ECApplicationException;
import com.ibm.commerce.exception.ECException;
import com.ibm.commerce.exception.ParameterNotFoundException;
import com.ibm.commerce.ras.ECMessage;
import com.ibm.commerce.ras.ECMessageHelper;
import com.ibm.commerce.sample.databeans.MyNewDataBean;
import com.ibm.commerce.sample.databeans.XBonusEJBDataBean;
import com.ibm.commerce.server.ECConstants;
import com.ibm.commerce.user.objects.UserAccessBean;
import com.ibm.commerce.user.objects.UserRegistryAccessBean;
import com.ibm.ejb.sample.XBonusEJBAccessBean;
public class MyNewControllerCmdImpl extends ControllerCommandImpl implements
MyNewControllerCmd {
String userName;
Integer points;
AccessVector resources = null;
//BonusAccessBean bonusAccessBean;
XBonusEJBAccessBean bonusAccessBean;
UserRegistryAccessBean userRegistryAccessBean;
@Override
public AccessVector getResources() throws ECException {
String refNum = null;
try {
userRegistryAccessBean = new UserRegistryAccessBean();
userRegistryAccessBean = userRegistryAccessBean
.findByUserLogonId(getUserName());
refNum = userRegistryAccessBean.getUserId();
System.out.println("++++++++++++++++"+refNum);
} catch (Exception e) {
e.printStackTrace();
}
bonusAccessBean = new XBonusEJBAccessBean();//new BonusAccessBean();
if (refNum != null) {
try {
bonusAccessBean.setInitKey_memberId(new Long(refNum));
bonusAccessBean.refreshCopyHelper();
resources = new AccessVector(bonusAccessBean);
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (FinderException e) {
UserAccessBean uab = new UserAccessBean();
uab.setInitKey_MemberId(refNum);
resources = new AccessVector(uab);
} catch (NamingException e) {
e.printStackTrace();
}
}
return resources;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getPoints() {
return points;
}
public void setPoints(Integer points) {
this.points = points;
}
@Override
public void performExecute() throws ECException {
// TODO Auto-generated method stub
super.performExecute();
TypedProperty resProp = new TypedProperty();
resProp.put("controllerParm1", "Hello From IBM!!!");
resProp.put("controllerParm2", "Have a Nice Day!!!");
MyNewDataBean mndb = new MyNewDataBean();
mndb.setCalledByControllerCmd(true);
mndb.setCallingCommandName(this.getClass().getName());
mndb.setUserName(getUserName());
mndb.setPoints(getPoints());
resProp.put("mndbInstance", mndb);
MyNewTaskCmd taskCmd = null;
try {
taskCmd = (MyNewTaskCmd) CommandFactory.createCommand(
"com.ibm.commerce.sample.commands.MyNewTaskCmd",
getStoreId());
taskCmd.setCommandContext(getCommandContext());
taskCmd.setInputPoints(getPoints());
taskCmd.setInputUserName(getUserName());
taskCmd.setXBonusEJBAccessBean(bonusAccessBean);
taskCmd.setUserRegistryAccessBean(userRegistryAccessBean);
taskCmd.execute();
if (taskCmd.getGreetings() != null)
resProp.put("taskOutputGreetings", taskCmd.getGreetings());
if (taskCmd.getFoundUserId() != null)
resProp.put("taskOutputUserId", taskCmd.getFoundUserId());
//BonusDataBean bdb=new BonusDataBean(bonusAccessBean);
XBonusEJBDataBean bdb = new XBonusEJBDataBean(bonusAccessBean);
if(taskCmd.getOldBonusPoints()!=null)
resProp.put("oldBonusPoints", taskCmd.getOldBonusPoints());
System.out.println("*******************"+bdb.getBonusPoint());
resProp.put("bdbInstance", bdb);
} catch (Exception e) {
// TODO: handle exception
}
resProp.put(ECConstants.EC_VIEWTASKNAME, "MyNewView");
setResponseProperties(resProp);
}
@Override
public void validateParameters() throws ECException {
// TODO Auto-generated method stub
super.validateParameters();
TypedProperty reqProp = getRequestProperties();
try {
setUserName(reqProp.getString("input1"));
} catch (ParameterNotFoundException e) {
throw new ECApplicationException(
ECMessage._ERR_MISSING_CMD_PARAMETER, this.getClass()
.getName(), "validateParameters", ECMessageHelper
.generateMsgParms(e.getParamName()));
}
setPoints(reqProp.getInteger("input2", 0));
}
}
No comments:
Post a Comment