All pastes #766922 Raw Edit

Something

public text v1 · immutable
·published 2007-11-09 08:56 UTC
rendered paste body
package fr.cvf.vodoo.zne.web.controller.page;

import fr.cvf.pgc.dao.DAOException;
import fr.cvf.vodoo.ihm.zne.ajax.dto.AbstractBclMenuItem;
import fr.cvf.vodoo.ihm.zne.ajax.dto.MovieInfosBean;
import fr.cvf.vodoo.ihm.zne.ajax.dto.MovieInfosBeanFactory;
import fr.cvf.vodoo.ihm.zne.ajax.dto.PaymentModeBclMenuItem;
import fr.cvf.vodoo.ihm.zne.domain.service.BasketService;
import fr.cvf.vodoo.ihm.zne.domain.service.payment.IPaymentStrategyFactory;
import fr.cvf.vodoo.pgc.facade.Movie;
import fr.cvf.vodoo.pgc.facade.User;
import fr.cvf.vodoo.pgc.facade.impl.basket.PaymentMethod;
import fr.cvf.vodoo.zne.web.bean.PaymentModeResult;
import fr.cvf.vodoo.zne.web.security.CheckSession;
import fr.cvf.vodoo.zne.web.service.ZneUrlFactory;
import fr.cvf.vodoo.zne.web.session.Visit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

/**
 * @author ecruciani
 */
@CheckSession
public class PaymentChoiceController extends SimpleFormController {
    /** Movie infos bean Factory */
    private MovieInfosBeanFactory movieInfosBeanFactory;
    /** Payment Strategy Factory */
    private IPaymentStrategyFactory paymentStrategyFactory;
    /** Basket Service */
    private BasketService basketService;
    /** User vist */
    private Visit visit;
    /** ZneUrlFactory*/
    private ZneUrlFactory zneUrlFactory;

    
    /**
     * indique si l'utilisateur peut passer la phase de paiement
     * @param user
     * @return
     * @throws DAOException
     */
    private boolean isFreePaymentApplicable() throws DAOException {
        boolean freePaymentApplicable = false;
    
        User user = visit.getUser();
        
        if  (user.isWhiteUser() ) {
            if ((user.isDemoUser() && user.isDemoUserUnderCeiling()) || user.isTestUser()) {
                freePaymentApplicable = true;
            }
        }
        return freePaymentApplicable;
    }
    
    /**
     * (non-Javadoc)
     * 
     * @see org.springframework.web.servlet.mvc.SimpleFormController#showForm(javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse, org.springframework.validation.BindException,
     *      java.util.Map)
     */
    @Override
    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors,
            Map controlModel) throws Exception {

        Movie m = this.basketService.getMovie();

        // only display form is price > 0, otherwise confirm directly
        if (m.getLowestPrice() == 0) {
            return goConfirmationWithPayment(PaymentType.FREE_ITEM);
        } else 
        if(isFreePaymentApplicable()) {
        	return goConfirmationWithPayment(PaymentType.FREE);
        } else {
        	return goConfirmationWithPayment(PaymentType.WPMS);
        }
        
        //return super.showForm(request, response, errors, controlModel);
    }

    /**
     * @param paymentMode
     * @return
     */
    private ModelAndView goConfirmationWithPayment(PaymentType paymentMode) {
      
    	PaymentMethod payment = this.paymentStrategyFactory.createPaymentStrategy(paymentMode).choosePaymentMode();
        this.visit.getBasket().setPrimaryPaymentMethod(payment);
       
        return new ModelAndView("redirect:/paymentConfirmation.do", new HashMap<String, Object>());
    }

    /**
     * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(java.lang.Object)
     */
    @Override
    protected ModelAndView onSubmit(Object commandObject) throws Exception {
        PaymentModeResult paymentModeResult = (PaymentModeResult) commandObject;
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("paymentModeResult : " + paymentModeResult.toString());
            this.logger.debug("Visit is null ? " + (this.visit == null));
            this.logger.debug("user is null ?: " + (this.visit.getUser() == null));
        }

        return goConfirmationWithPayment(paymentModeResult.getPaymentMode());
    }

    /**
     * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
     */
    @Override
    protected Object formBackingObject(HttpServletRequest request) throws Exception {
        this.logger.debug("formBackingObject() return new PaymentModeResult ");
        return new PaymentModeResult();
    }

    /**
     * initailisation de la vue
     * 
     * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest,
     *      java.lang.Object, org.springframework.validation.Errors)
     */
    @Override
    protected Map<String, Object> referenceData(HttpServletRequest request, Object commandObject, Errors errors)
            throws Exception {
        Map<String, Object> model = new HashMap<String, Object>();
        String jsonItems = buildMenuItems(request).toString();
        model.put("jsonItems", jsonItems);

        int marqueurFilm = this.basketService.getMovie().getMarqueur();
        int marqueurOrigine = this.basketService.getOrigine().getMarqueur();
        MovieInfosBean movieInfosBean = this.movieInfosBeanFactory.createMovieInfosBean(marqueurFilm, marqueurOrigine);
        model.put("backUrl", this.zneUrlFactory.buildMovieUrl());
        model.put("movieInfosBean", movieInfosBean);

        return model;
    }

    /**
     * @param request
     * @return
     */
    private JSONArray buildMenuItems(HttpServletRequest request) {
        List<AbstractBclMenuItem> items = new ArrayList<AbstractBclMenuItem>();
        items.add(new PaymentModeBclMenuItem("facture Orange", PaymentType.WPMS));
        items.add(new PaymentModeBclMenuItem("code cadeau", PaymentType.OTA));
        return JSONArray.fromObject(items);
    }

    /**
     * @param movieInfosBeanFactory
     */
    @Required
    public void setMovieInfosBeanFactory(MovieInfosBeanFactory movieInfosBeanFactory) {
        this.movieInfosBeanFactory = movieInfosBeanFactory;
    }

    /**
     * @param paymentStrategyFactory
     */
    @Required
    public void setPaymentStrategyFactory(IPaymentStrategyFactory paymentStrategyFactory) {
        this.paymentStrategyFactory = paymentStrategyFactory;
    }

    /**
     * @param basketService
     */
    @Required
    public void setBasketService(BasketService basketService) {
        this.basketService = basketService;
    }

    /**
     * @param visit
     */
    @Required
    public void setVisit(Visit visit) {
        this.visit = visit;
    }

    @Required
	public void setZneUrlFactory(ZneUrlFactory zneUrlFactory) {
		this.zneUrlFactory = zneUrlFactory;
	}
}







	<!-- VOD_PAY_LS001 -->
	<bean name="/paymentChoice.do" class="fr.cvf.vodoo.zne.web.controller.page.PaymentChoiceController" >
        <property name="formView" value="VOD_PAY_LS001"/>
        <property name="commandName" value="paymentModeResult"/>
        <property name="commandClass" value="fr.cvf.vodoo.zne.web.bean.PaymentModeResult"/>	
		<property name="movieInfosBeanFactory" ref="movieInfosBeanFactory"/>
		<property name="paymentStrategyFactory" ref="paymentStrategyFactory"/>
		<property name="basketService" ref="basketService"/>
		<property name="zneUrlFactory" ref="zneUrlFactory"/>
		<property name="visit" ref="visit"/>
	</bean>



<!DOCTYPE HTML fullscreen>
<html>
<HEAD>
<META NAME=media VALUE="tv"> 
<style>
	BODY, SPAN, DIV, TD, INPUT {font: TiresiasOrange;}
</style>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META http-equiv="PRAGMA" content="NO-CACHE" />
<link rel="stylesheet" href="style.css" type="text/css" />

<#import "macros/bcl.ftl" as bcl />
<#import "macros/utils.ftl" as utils />
<#import "spring.ftl" as spring />
<@utils.includeJs jsName="core.js" />
<@utils.includeJs jsName="Toolbox.js" />
<@utils.includeJs jsName="Observable.js" />
<@utils.includeJs jsName="HtmlEventManager.js" />
<@utils.includeJs jsName="ScrollComponent.js" />

</HEAD>

<@bcl.head menuAuthorizedToUseHeadZone=false>
   	var items = ${jsonItems};
    bclMenu.buildMenu(items, 0);
    bclMenu.focus();
    bclMenu.register(Bcl.BCL_VALID_EVENT, function(data) { 
		$('paymentMode').value = data.getCurrentItem().paymentMode;
		$('paymentForm').submit(); 
	});
    bclMenu.register(Bcl.BCL_BACK_EVENT, function(data) {
    	document.location.href="${backUrl}";
    });
</@bcl.head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#1e1e1e">
<@spring.bind "paymentModeResult.*"/>
<form id="paymentForm" method="POST" action="<@spring.url '/paymentChoice.do'/>">
	<@spring.formHiddenInput "paymentModeResult.paymentMode"/>
</form>
<table cellspacing="0" cellpadding="0" border="0" width="720">
	<tr class="blackBG">
		<td width="40" height="30"> </td>  <!--   0 , 40  -->
		<td width="20"> </td>              <!--  40 , 20  -->
		<td width="205"> </td>             <!--  60 , 265 -->
		<td width="20"> </td>              <!-- 265 , 285 -->
		<td width="332"> </td>             <!-- 285 , 617 -->
		<td width="38"> </td>              <!-- 617 , 655 -->
		<td width="20"> </td>              <!-- 655 , 675 -->
		<td width="45"> </td>              <!-- 675 , 720 -->
	</tr>
	<tr class="blackBG">
		<td height="43" colspan="2"> </td>
		<td colspan="3">
			<table cellspacing="0" cellpadding="0" border="0">
				<td width="387" class="blackBG" valign="middle">commande </td>
				<td width="50"> </td>
				<td width="50"> </td>
				<td width="50">&nbsp;</td>
				<td width="20"> </td>
			</table>
		</td>
		<td colspan="2" class="tiny"><@utils.hour /></td>
		<td> </td>
	<tr>
	<tr>
		<td height="2" colspan="8" class="orangeBG"> </td>
	</tr>
	<tr>
		<td height="5" colspan="8"> </td>
	</tr>
	<tr>
		<td height="139" colspan="2"> </td>
		<td height="139" colspan="4" valign="top" class="big">Choisissez votre mode de paiement. </td>
		<td colspan="2"> </td>
	</tr>
	<tr>
		<td height="40" colspan="2" class="orangeBG"> </td>
		<td valign="top" class="orangeBG">${movieInfosBean.getPrice()}</td>
		<td class="whiteBG"><img src="images/picto_arrowsUpDown.gif"/></td>
		<@bcl.interaction />
		<td colspan="2" class="orangeBG"><img src="images/picto_arrowRight_1.gif"/></td>
		<td class="orangeBG"> </td>
	</tr>
	<tr>
		<td height="300"> </td>
		<td colspan="2" valign="top"><img src="${movieInfosBean.getCover()}" width="225" height="300"></td>
		<td> </td>
		<td colspan="4" valign="top">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td height="252" valign="top" align="left">
						<@bcl.body />
					</td>
				</tr>
			</table>   
			<table width="100%" border="0" cellspacing="0" cellpadding="0" height="40">
				<tr>
					<td width="290">&nbsp;</td>
					<td align="right" class="small">&nbsp;</td>
					<td width="45">&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>