Filtrování podniků podle kategorie.
1 package cz.frantovo.nekurak.ejb;
3 import cz.frantovo.nekurak.dao.PodnikDAO;
4 import cz.frantovo.nekurak.dto.Kategorie;
5 import cz.frantovo.nekurak.dto.Komentar;
6 import cz.frantovo.nekurak.dto.Podnik;
7 import cz.frantovo.nekurak.dto.VysledekHlasovani;
8 import cz.frantovo.nekurak.ext.Geo;
9 import cz.frantovo.nekurak.ext.Geo.Souradnice;
10 import cz.frantovo.nekurak.ext.Texy;
11 import cz.frantovo.nekurak.util.Komentare;
12 import cz.frantovo.nekurak.vyjimky.KomentarovaVyjimka;
13 import cz.frantovo.nekurak.vyjimky.TexyVyjimka;
14 import java.util.Collection;
15 import java.util.HashSet;
17 import java.util.logging.Logger;
18 import javax.annotation.Resource;
19 import javax.annotation.security.RolesAllowed;
21 import javax.ejb.SessionContext;
22 import javax.ejb.Stateless;
29 public class PodnikEJB implements PodnikRemote {
31 private static final Logger log = Logger.getLogger(PodnikEJB.class.getSimpleName());
33 private PodnikDAO podnikDAO;
35 private SessionContext ctx;
37 public Collection<Podnik> getPodniky() {
38 Collection<Podnik> vysledek = podnikDAO.getPodniky();
42 public Collection<Podnik> getPodniky(Kategorie kategorie) {
43 Collection<Podnik> vysledek = podnikDAO.getPodniky(kategorie);
47 public Podnik getPodnik(int id) {
48 return podnikDAO.getPodnik(id);
51 @RolesAllowed("opravneny")
52 public void zalozPodnik(Podnik p) {
53 p.setSpravce(ctx.getCallerPrincipal().getName());
57 @RolesAllowed("opravneny")
58 public void upravPodnik(Podnik p) {
62 public int dopocitejSouradnice() {
64 * TODO: refaktorovat, změnit datové typy, souřadnice…
67 int pocetAktualizovanych = 0;
69 for (Podnik p : podnikDAO.getPodnikyBezSouradnic()) {
70 Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto());
72 pocetAktualizovanych++;
73 p.setSirka(s.getSirka());
74 p.setDelka(s.getDelka());
79 return pocetAktualizovanych;
82 public void hlasuj(int podnik, boolean hlas, String ipAdresa) {
84 podnikDAO.hlasuj(podnik, hlas, ipAdresa);
87 public VysledekHlasovani getVysledekHlasovani(Podnik podnik) {
88 return podnikDAO.getVysledekHlasovani(podnik);
91 private void kontrolaKomentare(Komentar k) throws TexyVyjimka, KomentarovaVyjimka {
92 k.setUzivatel(ctx.getCallerPrincipal().getName());
95 if (k.getKomentar() == null || k.getKomentar().length() < 1) {
96 throw new KomentarovaVyjimka("Nechceme prázdné komentáře.", null);
99 /** Převedeme na XML */
100 switch (k.getTyp()) {
102 k.setKomentar(Komentare.upravProstyText(k.getKomentar()));
106 k.setKomentar(t.preved(k.getKomentar()));
109 k.setKomentar(Komentare.upravXHTML(k.getKomentar()));
112 /** Přidáme kořenový element */
113 k.setKomentar(Komentare.obal(k.getKomentar()));
115 /** Zkontrolujeme XML */
116 Komentare.zkontroluj(k.getKomentar());
119 @RolesAllowed("opravneny")
120 public Komentar komentuj(Komentar k, boolean uloz) throws KomentarovaVyjimka, TexyVyjimka {
121 kontrolaKomentare(k);