Package com.evasion.client.controler.booktravel.secure

Source Code of com.evasion.client.controler.booktravel.secure.BookTravelForm

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.client.controler.booktravel.secure;

import com.evasion.common.Constante;
import com.evasion.entity.booktravel.BookTravel;
import com.evasion.exception.EvasionException;
import com.evasion.module.travel.ITravelModule;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author sglon
*/
@ManagedBean()
@ViewScoped
public class BookTravelForm {

    /**
     * Logger *
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(BookTravelForm.class);

    @EJB
    private ITravelModule bookTravelEJB;

    private BookTravel book;

    @PostConstruct
    public void init() {
        try {
            LOGGER.debug("Initialisation du Bean Manager BookTravelForm");
            FacesContext ctx = FacesContext.getCurrentInstance();
            Map params = FacesContext.getCurrentInstance().
                    getExternalContext().getRequestParameterMap();
            String id = (String) params.get("id");
            if (id == null || id.isEmpty()) {
                LOGGER.debug("Initialisation du bookTravel");
                book = new BookTravel();
            } else {
                book = bookTravelEJB.findBooktravelWithoutRoadMap(
                        Long.parseLong(id));
            }
        } catch (EvasionException ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Le carnet de voyage demandé n'a pas été trouvé", ex.toString()));
            LOGGER.error("Le carnet de voyage demandé n'a pas été trouvé", ex);
        }
    }

    public String annulContribution() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ctx.getExternalContext().getSessionMap().remove("currentBookTravel");
        return "booktravel/index.xhtml"; //@TODO a changer l'URL de retour.
    }

    public BookTravel getBook() {
        return book;
    }

    public void setBook(BookTravel book) {
        this.book = book;
    }

    /**
     * Action de validation du formulaire.
     *
     * @return
     * <code>Constante.FAIL_ACTION</code> si erreur de lavalidation; <br> sinon
     * renvoi la page de destination.
     */
    public String validContribution() {
        LOGGER.debug("Demande de validation d'une contribution au sein d'une roadMap");
        String result = null;
        try {
            bookTravelEJB.createOrUpdateBookTravel(book);
        } catch (EvasionException ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Erreur dans la création/modification de la feuille de route", ex.toString()));
            result = Constante.FAIL_ACTION;
        } catch (EJBException ex) {
            LOGGER.error("Erreur technique sur appel des couche métier", ex);
            FacesContext ctx = FacesContext.getCurrentInstance();
            ctx.getExternalContext().getSessionMap().remove("currentRoadMap");
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Erreur d'appel des couche métier", ex.toString()));
            result = Constante.FAIL_ACTION;
        }
        if (result == null) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Les données ont été correctement sauvegardé", ""));
            result = Constante.SUCCESS_ACTION;
        }
        return result;

    }
}
TOP

Related Classes of com.evasion.client.controler.booktravel.secure.BookTravelForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.