java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikEJB.java
author František Kučera <franta-hg@frantovo.cz>
Tue Apr 27 19:04:20 2010 +0200 (2010-04-27)
changeset 110 c2590a59a02a
parent 107 e8371105fcc8
child 119 d91f600c4645
permissions -rw-r--r--
Hlasování: funguje zobrazování výsledků i posílání hlasů.
franta-hg@28
     1
package cz.frantovo.nekurak.ejb;
franta-hg@28
     2
franta-hg@39
     3
import cz.frantovo.nekurak.dao.PodnikDAO;
franta-hg@28
     4
import cz.frantovo.nekurak.dto.Podnik;
franta-hg@107
     5
import cz.frantovo.nekurak.dto.VysledekHlasovani;
franta-hg@100
     6
import cz.frantovo.nekurak.ejb.Geo.Souradnice;
franta-hg@110
     7
import java.lang.String;
franta-hg@28
     8
import java.util.Collection;
franta-hg@110
     9
import java.util.Iterator;
franta-hg@110
    10
import java.util.Set;
franta-hg@107
    11
import java.util.logging.Logger;
franta-hg@63
    12
import javax.annotation.Resource;
franta-hg@40
    13
import javax.annotation.security.RolesAllowed;
franta-hg@39
    14
import javax.ejb.EJB;
franta-hg@63
    15
import javax.ejb.SessionContext;
franta-hg@28
    16
import javax.ejb.Stateless;
franta-hg@28
    17
franta-hg@28
    18
/**
franta-hg@28
    19
 *
franta-hg@28
    20
 * @author fiki
franta-hg@28
    21
 */
franta-hg@28
    22
@Stateless
franta-hg@39
    23
public class PodnikEJB implements PodnikRemote {
franta-hg@28
    24
franta-hg@107
    25
    private static final Logger log = Logger.getLogger(PodnikEJB.class.getSimpleName());
franta-hg@39
    26
    @EJB
franta-hg@50
    27
    private PodnikDAO podnikDAO;
franta-hg@63
    28
    @Resource
franta-hg@63
    29
    private SessionContext ctx;
franta-hg@28
    30
franta-hg@28
    31
    public Collection<Podnik> getPodniky() {
franta-hg@39
    32
	Collection<Podnik> vysledek = podnikDAO.getPodniky();
franta-hg@39
    33
	return vysledek;
franta-hg@28
    34
    }
franta-hg@40
    35
franta-hg@100
    36
    public Podnik getPodnik(int id) {
franta-hg@100
    37
	return podnikDAO.getPodnik(id);
franta-hg@100
    38
    }
franta-hg@100
    39
franta-hg@40
    40
    @RolesAllowed("opravneny")
franta-hg@40
    41
    public void zalozPodnik(Podnik p) {
franta-hg@63
    42
	p.setSpravce(ctx.getCallerPrincipal().getName());
franta-hg@56
    43
	podnikDAO.zaloz(p);
franta-hg@40
    44
    }
franta-hg@40
    45
franta-hg@40
    46
    @RolesAllowed("opravneny")
franta-hg@40
    47
    public void upravPodnik(Podnik p) {
franta-hg@40
    48
	podnikDAO.uloz(p);
franta-hg@40
    49
    }
franta-hg@100
    50
franta-hg@100
    51
    public int dopocitejSouradnice() {
franta-hg@100
    52
	/**
franta-hg@100
    53
	 * TODO:    refaktorovat, změnit datové typy, souřadnice…
franta-hg@100
    54
	 */
franta-hg@100
    55
	Geo g = new Geo();
franta-hg@100
    56
	int pocetAktualizovanych = 0;
franta-hg@100
    57
franta-hg@102
    58
	for (Podnik p : podnikDAO.getPodnikyBezSouradnic()) {
franta-hg@100
    59
	    Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto());
franta-hg@100
    60
	    if (s != null) {
franta-hg@100
    61
		pocetAktualizovanych++;
franta-hg@100
    62
		p.setSirka(s.getSirka());
franta-hg@100
    63
		p.setDelka(s.getDelka());
franta-hg@100
    64
		podnikDAO.uloz(p);
franta-hg@100
    65
	    }
franta-hg@100
    66
	}
franta-hg@100
    67
franta-hg@100
    68
	return pocetAktualizovanych;
franta-hg@100
    69
    }
franta-hg@107
    70
franta-hg@107
    71
    public void hlasuj(int podnik, boolean hlas, String ipAdresa) {
franta-hg@110
    72
franta-hg@107
    73
	podnikDAO.hlasuj(podnik, hlas, ipAdresa);
franta-hg@107
    74
    }
franta-hg@107
    75
franta-hg@107
    76
    public VysledekHlasovani getVysledekHlasovani(int podnik) {
franta-hg@107
    77
	return podnikDAO.getVysledekHlasovani(podnik);
franta-hg@107
    78
    }
franta-hg@28
    79
}