Package com.evasion.client.controler.booktravel

Source Code of com.evasion.client.controler.booktravel.BookTravelView

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

import com.evasion.client.controler.ApplicationContext;
import com.evasion.common.Utils;
import com.evasion.ejb.local.ParametreManagerLocal;
import com.evasion.entity.booktravel.BookTravel;
import com.evasion.entity.booktravel.RoadMap;
import com.evasion.exception.EvasionException;
import com.evasion.module.travel.ITravelModule;
import com.evasion.module.travel.ITravelStep;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import org.primefaces.model.map.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author sebastien
*/
@ManagedBean
public class BookTravelView {

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

    @EJB
    ParametreManagerLocal paramEJB;

    @EJB
    ITravelModule bookTravelEJB;

    @ManagedProperty(name = "", value = "#{applicationContext}")
    private ApplicationContext applicationContext;

    private Long currentBookTravelID;

    private BookTravel currentBookTravel;

    private List<RoadMap> roadMaps;

    private Map<Long, String> bookMemeAuteur;

    @PostConstruct
    public void init() {
        LOGGER.debug("Init du bean IndexBookTravel");
        try {
            Map params = FacesContext.getCurrentInstance().
                    getExternalContext().getRequestParameterMap();
            String id = (String) params.get("bkId");
            if (Utils.isEmpty(id)) {
                currentBookTravelID = (Long) FacesContext.getCurrentInstance().
                        getExternalContext().getSessionMap().
                        get("currentBookTravelID");
            } else {
                currentBookTravelID = Long.parseLong(id);
            }
            this.currentBookTravel = bookTravelEJB.findBooktravelWithoutRoadMap(
                    currentBookTravelID);
            FacesContext.getCurrentInstance().
                    getExternalContext().getSessionMap().put("currentBookTravelID", currentBookTravel.getId());

            this.roadMaps = bookTravelEJB.findNewestRoadMap(currentBookTravel.getId(), 5);
            this.bookMemeAuteur = bookTravelEJB.findBooktravelForUser(currentBookTravel.getUsername());
            this.bookMemeAuteur.remove(currentBookTravel.getId());
        } 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 BookTravel getBookTravel() {
        return currentBookTravel;
    }

    public void setBookTravel(BookTravel bookTravel) {
        this.currentBookTravel = bookTravel;
    }

    public List<RoadMap> getRoadMaps() {
        return roadMaps;
    }

    public void setRoadMaps(List<RoadMap> roadMap) {
        this.roadMaps = roadMap;
    }

    public Map<Long, String> getBookMemeAuteur() {
        return bookMemeAuteur;
    }

    public void setBookMemeAuteur(Map<Long, String> bookMemeAuteur) {
        this.bookMemeAuteur = bookMemeAuteur;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public MapModel getMapModel() {
        MapModel model = new DefaultMapModel();

        List<ITravelStep> steps = bookTravelEJB.getBookTravelStep(currentBookTravelID);
        List<LatLng> paths = new ArrayList<LatLng>(steps.size());
        Polyline polyline = new Polyline();
        polyline.setStrokeWeight(10);
        polyline.setStrokeColor("#FF9900");
        polyline.setStrokeOpacity(0.7);


        LatLng latLng;
        for (ITravelStep step : steps) {
            if (step.getStart() != null) {
                latLng = new LatLng(step.getStart().getLatitude(), step.getStart().getLongitude());
                paths.add(latLng);
                model.addOverlay(new Marker(latLng, step.getTitle()));
            }
        }
        // ajout de l'arrive de la dernière étape
        if (steps.size() > 1 && steps.get(steps.size() - 1) != null) {
            ITravelStep lastStep = steps.get(steps.size() - 1);
            if (lastStep.getEnd() != null) {
                latLng = new LatLng(lastStep.getEnd().getLatitude(), lastStep.getEnd().getLongitude());
                paths.add(latLng);
            }
        }
        polyline.setPaths(paths);
        model.addOverlay(polyline);

        return model;
    }
}
TOP

Related Classes of com.evasion.client.controler.booktravel.BookTravelView

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.