Hi Using this code u can solve ur problem
package com.passkey.resdesk.web.action.event;
import com.passkey.core.datavo.common.AcceptedCardListVO;
import com.passkey.core.datavo.common.AcceptedCardVO;
import com.passkey.core.datavo.common.AcceptedCardVOType;
import com.passkey.core.datavo.common.AccessPrivilegeVO;
import com.passkey.core.datavo.common.CommerceCVO;
import com.passkey.core.datavo.common.CommerceProcessingV OType;
import com.passkey.core.datavo.common.CommerceVOType;
import com.passkey.core.datavo.common.EventCommerceListVO Type;
import com.passkey.core.datavo.common.EventCommerceVO;
import com.passkey.core.datavo.common.EventCommerceVOType ;
import com.passkey.core.datavo.common.GroupCommerceListVO Type;
import com.passkey.core.datavo.common.GroupCommerceVO;
import com.passkey.core.datavo.common.GroupCommerceVOType ;
import com.passkey.core.datavo.common.ObjectFactory;
import com.passkey.core.datavo.common.PKComponentRequestV O;
import com.passkey.core.framework.infraservice.exception. ExceptionService;
import com.passkey.core.framework.infraservice.logging.Lo ggingService;
import com.passkey.core.framework.infraservice.logging.Pa sskeyLogger;
import com.passkey.core.framework.ui.session.ResdeskSessi onManager;
import com.passkey.core.framework.ui.template.TemplateCon stants;
import com.passkey.core.util.ConstantDeclareI;
import com.passkey.core.util.DateValidator;
import com.passkey.core.util.PasskeyConstants;
import com.passkey.core.util.PasskeyUtils;
import com.passkey.core.util.PropertyFileReader;
import com.passkey.resdesk.web.action.ResdeskPageAction;
import com.passkey.resdesk.web.action.ResdeskXAction;
import com.passkey.resdesk.web.actionform.event.CommerceF orm;
import com.passkey.resdesk.web.delegate.PKResdeskXDelegat e;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBException;
public class CommerceAction extends DispatchAction {
LoggingService logService = LoggingService.getInstance();
PasskeyLogger logger = logService.getLogger(this.getClass().getName());
private SimpleDateFormat formatterSmalldate = new SimpleDateFormat(ConstantDeclareI.SMALL_DATE);
public ActionForward load(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
PKComponentRequestVO requestVO = null;
CommerceCVO commerceCVO = null;
List eventCommercelist = new ArrayList();
List groupCommercelist = new ArrayList();
List cancellationfee = new ArrayList();
logger.entering();
if (ResdeskPageAction.checkAndTouchLogin(request, response,
PasskeyUtils.getResDeskAppID().intValue())) {
return null; // session has expired
}
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
requestVO = session.getPKComponentRequestVO();
requestVO.setComponentTypeId(PKComponentRequestVO. COMMERCE);
commerceCVO = (CommerceCVO) pkResdeskXDelegate.load(requestVO);
AccessPrivilegeVO accessPriviligeVO = pkResdeskXDelegate.getAccessPrivileges(requestVO);
session.putSessionData(ConstantDeclareI.ACCESSPREV ILEGE,
accessPriviligeVO);
populateForm(form, commerceCVO);
EventCommerceVOType eventCommerceVOType = null;
GroupCommerceVOType groupCommerceVOType =null;
groupCommercelist = commerceCVO.getGroupCommerceListVO()
.getGroupCommerceVO();
eventCommercelist = commerceCVO.getEventCommerceListVO().getEventComme rceVO();
for (int i = 0; i < groupCommercelist.size(); i++) {
groupCommerceVOType = (GroupCommerceVOType) groupCommercelist.get(i);
cancellationfee.add(groupCommerceVOType);
}
//added for displaying Last Date to Charge.
for (int i = 0; i < eventCommercelist.size(); i++) {
eventCommerceVOType = (EventCommerceVOType)eventCommercelist.get(i);
if(eventCommerceVOType.getFeeTypeID()==PasskeyCons tants.ROOM_CXL_FEE){
request.setAttribute("eventCommerceVOType", eventCommerceVOType);
}
}
request.setAttribute(ConstantDeclareI.CANCELLATION FEE, cancellationfee);
ResdeskXAction.setBreadCrumbs(session,
TemplateConstants.COMMERCE_CANCELLATION_POLICY);
request.setAttribute("DISP_PAGE", "CancellationPolicy");
requestVO.setComponentTypeId(PKComponentRequestVO. GROUP_TYPE);
List attendeeTypeUICVOList = pkResdeskXDelegate.listAttendeeTypesByEvent(reques tVO);
//added to check no of attendee types should be atleast one.
if (attendeeTypeUICVOList.size() != 0) {
session.putSessionData("NoOfAttendees",
new Integer(attendeeTypeUICVOList.size()));
}else{
session.putSessionData("NoOfAttendees",new Integer(0));
}
return mapping.findForward("nxtpage");
}
public ActionForward submit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ObjectFactory objFactory = new ObjectFactory();
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
PKComponentRequestVO requestVO = null;
AcceptedCardListVO accList = null;
AcceptedCardVO acceptedCardVO = null;
CommerceForm commerceForm = (CommerceForm) form;
try {
accList = new ObjectFactory().createAcceptedCardListVO();
} catch (JAXBException e) {
ExceptionService.handleException(requestVO, e, logger);
}
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
if (commerceForm.getAmex()) {
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
acceptedCardVO.setName("American Express");
acceptedCardVO.setCardTypeID(102);
accList.getAcceptedCard().add(acceptedCardVO);
}
if (commerceForm.getDinersClub()) {
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
acceptedCardVO.setName("Diners Club");
acceptedCardVO.setCardTypeID(104);
accList.getAcceptedCard().add(acceptedCardVO);
}
if (commerceForm.getDiscover()) {
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
acceptedCardVO.setName("Discover");
acceptedCardVO.setCardTypeID(103);
accList.getAcceptedCard().add(acceptedCardVO);
}
if (commerceForm.getMasterCard()) {
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
acceptedCardVO.setName("MasterCard");
acceptedCardVO.setCardTypeID(101);
accList.getAcceptedCard().add(acceptedCardVO);
}
if (commerceForm.getVisa()) {
acceptedCardVO = new ObjectFactory().createAcceptedCardVO();
acceptedCardVO.setName("VISA");
acceptedCardVO.setCardTypeID(100);
accList.getAcceptedCard().add(acceptedCardVO);
}
CommerceCVO commerceCVO = null;
commerceCVO = objFactory.createCommerceCVO();
commerceCVO.setAcceptedCardListVO(accList);
commerceCVO.setCancellationInstructions(commerceFo rm.getInstructions());
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
requestVO = session.getPKComponentRequestVO();
requestVO.setComponentTypeId(PKComponentRequestVO. COMMERCE);
pkResdeskXDelegate.save(requestVO, commerceCVO);
return mapping.findForward("submit");
}
private void populateForm(ActionForm form, CommerceCVO commerceCVO) {
CommerceForm commerceForm = (CommerceForm) form;
List acceptedCards = new ArrayList();
acceptedCards = commerceCVO.getAcceptedCardListVO().getAcceptedCar d();
AcceptedCardVOType cardVOType = null;
for (int i = 0; i < acceptedCards.size(); i++) {
cardVOType = (AcceptedCardVOType) acceptedCards.get(i);
if (cardVOType.getName().equalsIgnoreCase(ConstantDec lareI.GL_AMERICAN_EXPRESS)) {
commerceForm.setAmex(true);
}
if (cardVOType.getName().equalsIgnoreCase(ConstantDec lareI.GL_DINERS_CLUB)) {
commerceForm.setDinersClub(true);
}
if (cardVOType.getName().equalsIgnoreCase(ConstantDec lareI.GL_DISCOVER)) {
commerceForm.setDiscover(true);
}
if (cardVOType.getName().equalsIgnoreCase(ConstantDec lareI.GL_VISA)) {
commerceForm.setVisa(true);
}
if (cardVOType.getName().equalsIgnoreCase(ConstantDec lareI.GL_MASTERCARD)) {
commerceForm.setMasterCard(true);
}
}
commerceForm.setInstructions(commerceCVO.getCancel lationInstructions());
}
public ActionForward saveCommerce(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ObjectFactory objFactory = new ObjectFactory();
SimpleDateFormat formatterSmalldate = new SimpleDateFormat(ConstantDeclareI.SMALL_DATE);
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
PKComponentRequestVO requestVO = null;
CommerceForm commerceForm = (CommerceForm) form;
EventCommerceVO eventCommerceVO = null;
GroupCommerceVO groupCommerceVO =null;
EventCommerceListVOType eventCommerceListVO = null;
GroupCommerceListVOType GroupCommerceListVO =null;
CommerceProcessingVOType CommerceProcessingVO =null;
EventCommerceVOType eventCommerceVOType = null;
CommerceCVO commerceCVO = null;
List eventCommercelist = new ArrayList();
ActionErrors errors = new ActionErrors();
//added for session expired.
if (ResdeskPageAction.checkAndTouchLogin(request, response,
PasskeyUtils.getResDeskAppID().intValue())) {
return null; // session has expired
}
try {
eventCommerceListVO = new ObjectFactory().createEventCommerceListVOType();
GroupCommerceListVO =new ObjectFactory().createGroupCommerceListVOType();
CommerceProcessingVO =new ObjectFactory().createCommerceProcessingVOType();
} catch (JAXBException e) {
ExceptionService.handleException(requestVO, e, logger);
}
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
requestVO = session.getPKComponentRequestVO();
requestVO.setComponentTypeId(PKComponentRequestVO. COMMERCE);
eventCommerceVO = new ObjectFactory().createEventCommerceVO();
groupCommerceVO =new ObjectFactory().createGroupCommerceVO();
commerceCVO = (CommerceCVO) pkResdeskXDelegate.load(requestVO);
eventCommercelist = commerceCVO.getEventCommerceListVO().getEventComme rceVO();
for (int i = 0; i < eventCommercelist.size(); i++) {
eventCommerceVOType = (EventCommerceVOType)eventCommercelist.get(i);
if(eventCommerceVOType.getFeeTypeID()==PasskeyCons tants.ROOM_CXL_FEE){
groupCommerceVO.setCancellationDate(eventCommerceV OType.getCancellationDate());
eventCommerceVO.setCancellationDate(eventCommerceV OType.getCancellationDate());
commerceForm.setCclastDate(formatterSmalldate.form at(new Date(
eventCommerceVOType.getCancellationDate().getTimeI nMillis())));
}
}
errors = commerceForm.validate(mapping, request);
if ((errors != null) && !errors.isEmpty()) {
saveErrors(request, errors);
request.setAttribute("StartDateError",new Boolean (true));
return (mapping.findForward("success"));
}
groupCommerceVO.setFeeValue(Float.parseFloat(comme rceForm.getAmount()));
groupCommerceVO.setProcessingFeeDate(commerceForm. getEventCommerceVO()
.getProcessingFeeDate());
//groupCommerceVO.setCancellationDate(commerceForm.g etEventCommerceVO()
// .getCancellationDate());
groupCommerceVO.setFeeTypeID(PasskeyConstants.ROOM _CXL_FEE);
eventCommerceVO.setFeeTypeID(PasskeyConstants.ROOM _CXL_FEE);
CommerceProcessingVO.setMerchantAccountName(Proper tyFileReader.getPasskeyProperty(
"STR_MER_ACC_NAME"));
CommerceProcessingVO.setMerchantID(PropertyFileRea der.getPasskeyProperty(
"MERCHANT_ID"));
CommerceProcessingVO.setProcessorName(PropertyFile Reader.getPasskeyProperty(
"STR_PROC_NAME"));
CommerceProcessingVO.setTerminalID(PropertyFileRea der.getPasskeyProperty(
"STR_TERMINAL_ID"));
CommerceProcessingVO.setVendorCode(PropertyFileRea der.getPasskeyProperty(
"STR_VENDOR_NAME"));
CommerceProcessingVO.setOwnerShortName(PropertyFil eReader.getPasskeyProperty(
"STR_OWNER_SHORT_NAME"));
CommerceProcessingVO.setOwnerDivisionName(Property FileReader.getPasskeyProperty(
"STR_OWNER_DIVISION_NAME"));
GroupCommerceListVO.getGroupCommerceVO().add(group CommerceVO);
eventCommerceListVO.getEventCommerceVO().add(event CommerceVO);
commerceCVO = objFactory.createCommerceCVO();
commerceCVO.setGroupCommerceListVO(GroupCommerceLi stVO);
commerceCVO.setEventCommerceListVO(eventCommerceLi stVO);
commerceCVO.setProcessingVO(CommerceProcessingVO);
//TODO set the old date in the requestVO
if(!(("").equalsIgnoreCase(commerceForm.getOldstar tDate()))){
Calendar cal = Calendar.getInstance();
cal.setTime(DateValidator.isValid(commerceForm.get OldstartDate(),Locale.US));
requestVO.setCustomPayload(cal);
}
pkResdeskXDelegate.save(requestVO, commerceCVO);
return mapping.findForward("success");
}
public ActionForward removeCommerce(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ObjectFactory objFactory = new ObjectFactory();
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
PKComponentRequestVO requestVO = null;
CommerceForm commerceForm = (CommerceForm) form;
CommerceVOType commerceVO =null;
try {
commerceVO =new ObjectFactory().createCommerceVOType();
} catch (JAXBException e) {
ExceptionService.handleException(requestVO, e, logger);
}
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
requestVO = session.getPKComponentRequestVO();
requestVO.setComponentTypeId(PKComponentRequestVO. COMMERCE);
commerceVO.setFeeValue(Float.parseFloat(request.ge tParameter("Value")));
Calendar cal =Calendar.getInstance();
cal.setTime(formatterSmalldate.parse((request.getP arameter("ProcDate")
.toString())));
commerceVO.setProcessingFeeDate(cal) ;
Calendar endCal =Calendar.getInstance();
endCal.setTime(formatterSmalldate.parse((request.g etParameter("EndDate")
.toString())));
commerceVO.setCancellationDate(endCal);
commerceVO.setFeeTypeID(PasskeyConstants.ROOM_CXL_ FEE);
pkResdeskXDelegate.remove(requestVO,commerceVO);
return mapping.findForward("success");
}
public ActionForward saveLastDateToCharge(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ObjectFactory objFactory = new ObjectFactory();
PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();
PKComponentRequestVO requestVO = null;
CommerceForm commerceForm = (CommerceForm) form;
EventCommerceVO eventCommerceVO = null;
EventCommerceListVOType eventCommerceListVO = null;
CommerceProcessingVOType CommerceProcessingVO =null;
GroupCommerceVO groupCommerceVO =null;
GroupCommerceListVOType GroupCommerceListVO =null;
GroupCommerceVOType groupCommerceVOType =null;
List groupCommercelist = new ArrayList();
CommerceCVO commerceCVO = null;
ActionErrors errors = new ActionErrors();
//added for session expired.
if (ResdeskPageAction.checkAndTouchLogin(request, response,
PasskeyUtils.getResDeskAppID().intValue())) {
return null; // session has expired
}
try {
eventCommerceListVO = new ObjectFactory().createEventCommerceListVOType();
GroupCommerceListVO =new ObjectFactory().createGroupCommerceListVOType();
CommerceProcessingVO =new ObjectFactory().createCommerceProcessingVOType();
} catch (JAXBException e) {
ExceptionService.handleException(requestVO, e, logger);
}
ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
requestVO = session.getPKComponentRequestVO();
errors = commerceForm.validateLastDate(mapping, request);
if ((errors != null) && !errors.isEmpty()) {
saveErrors(request, errors);
request.setAttribute("LastDateError",new Boolean (true));
return (mapping.findForward("success"));
}
requestVO.setComponentTypeId(PKComponentRequestVO. COMMERCE);
eventCommerceVO = new ObjectFactory().createEventCommerceVO();
eventCommerceVO.setFeeTypeID(PasskeyConstants.ROOM _CXL_FEE);
//TODO set Last Date To Charge
if(!(("").equalsIgnoreCase(commerceForm.getCclastD ate()))){
Calendar cal = Calendar.getInstance();
cal.setTime(DateValidator.isValid(commerceForm.get CclastDate(),Locale.US));
eventCommerceVO.setCancellationDate(cal);
}
commerceCVO = (CommerceCVO) pkResdeskXDelegate.load(requestVO);
groupCommercelist = commerceCVO.getGroupCommerceListVO().getGroupComme rceVO();
for (int i = 0; i < groupCommercelist.size(); i++) {
groupCommerceVOType = (GroupCommerceVOType)groupCommercelist.get(i);
if(groupCommerceVOType.getFeeTypeID()==PasskeyCons tants.ROOM_CXL_FEE){
commerceForm.setStartDate(formatterSmalldate.forma t(new Date(
groupCommerceVOType.getProcessingFeeDate().getTime InMillis())));
errors = commerceForm.CommerceBusinessValidation(mapping, request);
if ((errors != null) && !errors.isEmpty()) {
saveErrors(request, errors);
request.setAttribute("LastDateError",new Boolean (true));
return (mapping.findForward("success"));
}
}
}
eventCommerceListVO.getEventCommerceVO().add(event CommerceVO);
CommerceProcessingVO.setMerchantAccountName(Proper tyFileReader.getPasskeyProperty(
"STR_MER_ACC_NAME"));
CommerceProcessingVO.setMerchantID(PropertyFileRea der.getPasskeyProperty(
"MERCHANT_ID"));
CommerceProcessingVO.setProcessorName(PropertyFile Reader.getPasskeyProperty(
"STR_PROC_NAME"));
CommerceProcessingVO.setTerminalID(PropertyFileRea der.getPasskeyProperty(
"STR_TERMINAL_ID"));
CommerceProcessingVO.setVendorCode(PropertyFileRea der.getPasskeyProperty(
"STR_VENDOR_NAME"));
CommerceProcessingVO.setOwnerShortName(PropertyFil eReader.getPasskeyProperty(
"STR_OWNER_SHORT_NAME"));
CommerceProcessingVO.setOwnerDivisionName(Property FileReader.getPasskeyProperty(
"STR_OWNER_DIVISION_NAME"));
commerceCVO = objFactory.createCommerceCVO();
commerceCVO.setEventCommerceListVO(eventCommerceLi stVO);
commerceCVO.setProcessingVO(CommerceProcessingVO);
pkResdeskXDelegate.save(requestVO, commerceCVO);
return mapping.findForward("success");
}
}
Thanks and Regards,
SACHIN S.TATHOD
Patni Computer System Ltd.
Magarpatta City, Cyber City,
Tower 3,Level I & II,
Hadapsar,Pune - 411028
Mobile No:- +91-9881239401
Email ID:-
[email protected]