1 package cz.frantovo.nekurak.ejb;
3 import cz.frantovo.nekurak.dao.PodnikDAO;
4 import cz.frantovo.nekurak.dto.Komentar;
5 import cz.frantovo.nekurak.dto.Podnik;
6 import cz.frantovo.nekurak.dto.VysledekHlasovani;
7 import cz.frantovo.nekurak.ext.Geo;
8 import cz.frantovo.nekurak.ext.Geo.Souradnice;
9 import cz.frantovo.nekurak.ext.Texy;
10 import cz.frantovo.nekurak.util.Komentare;
11 import cz.frantovo.nekurak.vyjimky.KomentarovaVyjimka;
12 import cz.frantovo.nekurak.vyjimky.TexyVyjimka;
13 import java.util.Collection;
14 import java.util.logging.Logger;
15 import javax.annotation.Resource;
16 import javax.annotation.security.RolesAllowed;
18 import javax.ejb.SessionContext;
19 import javax.ejb.Stateless;
26 public class PodnikEJB implements PodnikRemote {
28 private static final Logger log = Logger.getLogger(PodnikEJB.class.getSimpleName());
30 private PodnikDAO podnikDAO;
32 private SessionContext ctx;
34 public Collection<Podnik> getPodniky() {
35 Collection<Podnik> vysledek = podnikDAO.getPodniky();
39 public Podnik getPodnik(int id) {
40 return podnikDAO.getPodnik(id);
43 @RolesAllowed("opravneny")
44 public void zalozPodnik(Podnik p) {
45 p.setSpravce(ctx.getCallerPrincipal().getName());
49 @RolesAllowed("opravneny")
50 public void upravPodnik(Podnik p) {
54 public int dopocitejSouradnice() {
56 * TODO: refaktorovat, změnit datové typy, souřadnice…
59 int pocetAktualizovanych = 0;
61 for (Podnik p : podnikDAO.getPodnikyBezSouradnic()) {
62 Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto());
64 pocetAktualizovanych++;
65 p.setSirka(s.getSirka());
66 p.setDelka(s.getDelka());
71 return pocetAktualizovanych;
74 public void hlasuj(int podnik, boolean hlas, String ipAdresa) {
76 podnikDAO.hlasuj(podnik, hlas, ipAdresa);
79 public VysledekHlasovani getVysledekHlasovani(int podnik) {
80 return podnikDAO.getVysledekHlasovani(podnik);
83 private void kontrolaKomentare(Komentar k) throws TexyVyjimka, KomentarovaVyjimka {
84 k.setUzivatel(ctx.getCallerPrincipal().getName());
87 if (k.getKomentar() == null || k.getKomentar().length() < 1) {
88 throw new KomentarovaVyjimka("Nechceme prázdné komentáře.", null);
91 /** Převedeme na XML */
94 k.setKomentar(Komentare.upravProstyText(k.getKomentar()));
98 k.setKomentar(t.preved(k.getKomentar()));
101 k.setKomentar(Komentare.upravXHTML(k.getKomentar()));
104 /** Přidáme kořenový element */
105 k.setKomentar(Komentare.obal(k.getKomentar()));
107 /** Zkontrolujeme XML */
108 Komentare.zkontroluj(k.getKomentar());
111 @RolesAllowed("opravneny")
112 public Komentar komentuj(Komentar k, boolean uloz) throws KomentarovaVyjimka, TexyVyjimka {
113 kontrolaKomentare(k);